日期转换器和编码过滤器

1)  在默认情况下,springmvc不能将String类型转成Date类型,必须自定义类型转换器

public class AdminAction extends AbstractCommandController{
    @Override
    protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
        binder.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
    }

2)spring提供的,专用于解决POST提交中文乱码问题,需要在web.xml文件中配置

<!-- 编码过滤器 -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>
    org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

posted on 2018-12-04 11:42  LoaderMan  阅读(285)  评论(0编辑  收藏  举报

导航