类型转换器(InitBinder 初始化绑定器)
2017-01-07 18:53
411 查看
单日期格式
导入jar包
创建FirstController.java
applicationContext.xml配置 包扫描器
效果展示图
提交成功
多日期格式
与单日期jar包相同
效果展示
一
二
三
提交成功
导入jar包
创建FirstController.java
@Controller public class FirstController { /** * @param binder */ @InitBinder public void initBinder(WebDataBinder binder){ //PropertyEditor //类 implements PropertyEditor //yyyy-MM-dd格式的时间 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); } @RequestMapping("/first.do") //类型转化工作一定是在真正的handler方法执行前执行的。 public String doFirst(Date birthday,int age) throws Exception{ System.out.println(birthday+"==============="); System.out.println(age+"==============="); return "/WELCOME.jsp"; } }
applicationContext.xml配置 包扫描器
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <!-- 配置包扫描器--> <context:component-scan base-package="cn.happy.controller"></context:component-scan> </beans>
效果展示图
提交成功
多日期格式
与单日期jar包相同
效果展示
一
二
三
提交成功
相关文章推荐
- Spring MVC(学习笔记六)控制器的注解(五) -之全局初始化绑定操作(@InitBinder)
- spring mvc使用@InitBinder 标签对表单数据绑定
- SpringMVC用InitBinder注解实现表单多对象精准绑定接收
- Spring表单的initBinder:绑定表单复杂属性
- spring mvc使用@InitBinder 标签对表单数据绑定
- spring mvc使用@InitBinder 标签对表单数据绑定
- spring mvc使用@InitBinder标签对表单数据绑定的方法
- SpringMvc @InitBinder 表单多对象精准绑定接收
- SpringMVC中利用@InitBinder来对页面数据进行解析绑定
- spring mvc使用@InitBinder 标签对表单数据绑定
- SpringMVC中利用@InitBinder来对表单数据进行解析绑定
- Spring表单的initBinder:绑定表单复杂属性
- @InitBinder对表单数据绑定解决String转换Date问题
- SpringMVC中利用@InitBinder来对页面数据进行解析绑定
- SpringMVC中利用@InitBinder来对页面数据进行解析绑定
- SpringMvc @InitBinder 表单多对象精准绑定接收
- spring mvc使用@InitBinder 标签对表单数据绑定
- spring mvc使用@InitBinder 标签对表单数据绑定
- spring mvc使用@InitBinder 标签对表单数据绑定
- InitBinder表单数据绑定编辑器