系列文章目录
提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
例如:第一章 Python 机器学习入门之pandas的使用
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 系列文章目录
- 前言
- 一、velocity?
- 二、使用步骤
- 1.引入库
- 2.veiw
- 总结
前言
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
一、velocity?
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
二、使用步骤
1.引入库
代码如下(示例):
<dependency> <groupId>com.shield-solutions</groupId> <artifactId>spring-velocity-adapter</artifactId> <version>1.0.0.RELEASE</version> </dependency>package cn.ucm.rubik.common.appconfig;import com.shieldsolutions.velocity.view.VelocityConfigurer;import com.shieldsolutions.velocity.view.VelocityViewResolver;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.ViewResolver;import java.util.Properties;/** * Created by ucmed on 2018/01/08. */@Configuration public class VelocityConfig{publicstaticfinal String INPUT_ENCODE="input.encoding";publicstaticfinal String OUTPUT_ENCODING="output.encoding";publicstaticfinal String CHARSET_UTF="UTF-8";publicstaticfinal String CONTENT_TYPE="text/html;charset=UTF-8";publicstaticfinal String TOOL_BOX_CONFIG_LOCATION="WEB-INF/toolbox.xml";@Value("${velocity.prefer.file.system.access}")private Boolean fileSystemAccess;@Value("${velocity.resource.loader.path}")private String loaderPath;@Value("${velocity.resource.loader.cache}")private Boolean loaderCache;/** * <bean id="viewResolver" * class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver"> * <property name="cache" value="false"/> * <property name="prefix" value=""/> * <property name="suffix" value=".vm"/> * <property name="viewClass" * value="com.ucmed.common.velocity.VelocityLayoutToolboxView"/> * <property name="contentType" value="text/html;charset=UTF-8"/> * <property name="toolboxConfigLocation" value="WEB-INF/toolbox.xml"/> * </bean> * @return */@Bean public ViewResolverviewResolver(){VelocityViewResolver viewResolver=newVelocityViewResolver();viewResolver.setCache(loaderCache);viewResolver.setPrefix("");viewResolver.setSuffix(".vm");viewResolver.setViewClass(com.ucmed.common.velocity.VelocityLayoutToolboxView.class);viewResolver.setContentType(CONTENT_TYPE);viewResolver.setToolboxConfigLocation(TOOL_BOX_CONFIG_LOCATION);returnviewResolver;}/** * <bean id="velocityConfigurer" * class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> * <property name="preferFileSystemAccess" value="${velocity.prefer.file.system.access}"/> * <property name="resourceLoaderPath" value="${velocity.resource.loader.path}"/> * <property name="velocityProperties"> * <props> * <prop key="input.encoding">UTF-8</prop> * <prop key="output.encoding">UTF-8</prop> * </props> * </property> * </bean> * @return */@Bean public VelocityConfigurervelocityConfigurer(){VelocityConfigurer vc=newVelocityConfigurer();vc.setResourceLoaderPath(loaderPath);vc.setPreferFileSystemAccess(fileSystemAccess);Properties p=newProperties();p.setProperty(INPUT_ENCODE,CHARSET_UTF);p.setProperty(OUTPUT_ENCODING,CHARSET_UTF);vc.setVelocityProperties(p);returnvc;}}2.veiw
代码如下(示例)
package com.ucmed.common.velocity; import com.shieldsolutions.velocity.view.VelocityLayoutView; import org.apache.velocity.context.Context; import org.apache.velocity.tools.Scope; import org.apache.velocity.tools.ToolManager; import org.apache.velocity.tools.view.ViewToolContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Map; /** * Spring3默认的 createVelocityContext 方法中采用的是 tools-1.x 的 ToolboxManager, * ServletToolboxManager等类 加载toolbox,但是 tools 2.x 中已经废弃了这些类,导致了无法加载tools 2.x。 * 所以,这里采用tools 2.x中新的 ToolManager方式重写此方法加载toolbox2.x。 */ public class VelocityLayoutToolboxView extends VelocityLayoutView { @Override protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { ViewToolContext ctx = new ViewToolContext(this.getVelocityEngine(), request, response, this.getServletContext()); if(this.getToolboxConfigLocation() != null) { ToolManager tm = new ToolManager(); tm.setVelocityEngine(this.getVelocityEngine()); tm.configure(this.getServletContext().getRealPath( this.getToolboxConfigLocation())); for(String scope : Scope.values()) { ctx.addToolbox(tm.getToolboxFactory().createToolbox(scope)); } } if(model != null && !model.isEmpty()) { ctx.putAll(model); } return ctx; } }总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。