Springmvc 注解驱动格式化实例
2017-06-22 22:14
218 查看
public class User { private String name; //可将形如1980-09-01的字符串转换为Date类型的birthday属性中 @DateTimeFormat(pattern = "yyyy-MM-dd") private Date birthday; //可将形如4,500.00的字符串转换到long类型的salary属性中 @NumberFormat(pattern = "#,###.##") private long salary; public long getSalary() { return salary; } public void setSalary(long salary) { this.salary = salary; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } }
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>首页</title> </head> <body> <form action="<c:url value="/showuser.html" />"> <table> <tr> <td> 用户名: </td> <td> <input type="text" name="name"/> </td> </tr> <tr> <td> 生日: </td> <td> <input type="text" name="birthday"/> </td> </tr> <tr> <td> 工资: </td> <td> <input type="text" name="salary"> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="提交"> </td> </tr> </table> </form> </body> </html>
@RequestMapping("showuser") public String showuser(User user){ System.out.println(user.getName()); System.out.println(user.getBirthday()); System.out.println(user.getSalary()); return "register"; }
<context:component-scan base-package="com.smart"/> <!--替换原来默认的,FormattingConversionServiceFactory实现了格式化功能--> <mvc:annotation-driven conversion-service="myconversionService"/> <bean id="myconversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp"/>
占旭鹏
Thu Sep 06 00:00:00 GMT+08:00 2012
1123
相关文章推荐
- SpringMVC的数据格式化-注解驱动的属性格式化
- DWR高级主题之DWR与spring集成(使用springMVC,并使用注解的实例)
- DWR高级主题之DWR与spring集成(不使用springMVC,但使用注解的实例)
- springMVC 注解实现实例 springMVC+ajax
- SpringMVC 找不到注解实例
- SpringMVC 用注解Annotation驱动的IoC功能@Autowired @Component
- SpringMVC 实例 --非注解
- 通过SpringMVC整合基于注解的JPA的实例教程代码下载
- spring mvc时间格式化(注解驱动格式化)
- 缓存初解(五)---SpringMVC基于注解的缓存配置--web应用实例
- springMVC初学实例(注解)
- SpringMVC 用注解Annotation驱动的IoC功能@Autowired @Component
- SpringMVC 用注解Annotation驱动的IoC功能@Autowired @Component
- springMVC3.0注解讲解附实例
- 微信企业号简单的OAuth2验证接口实例(使用SpringMVC非注解方式)
- DWR高级主题之DWR与spring集成(不使用springMVC,不使用注解的实例)
- 工作笔记(三):SpringMVC入门实例--全注解方式
- SpringMVC_SpringMVC3.0.5+Spring3.0.5+MyBatis3.0.4全注解实例详解
- springmvc学习-----用注解Annotation驱动的IoC功能@Autowired @Component
- springmvc注解配置例子的实例代码下载