读书人

Spring MVC的检讨机制填充

发布时间: 2012-10-27 10:42:26 作者: rapoo

Spring MVC的自省机制填充


//User实例
package spr.web;import java.util.Date;import java.text.SimpleDateFormat;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.propertyeditors.CustomDateEditor;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.WebDataBinder;import org.springframework.web.bind.annotation.InitBinder;import org.springframework.web.bind.annotation.RequestMapping;import spr.domain.*;import spr.service.*;@Controller@RequestMapping("/user.htm")public class UserController {@Autowiredprivate UserServiceAble userService;//日期类型映射器@InitBinderpublic void initBinder(WebDataBinder binder){SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd");binder.registerCustomEditor(Date.class, new CustomDateEditor(df, false));}@RequestMapping(params="op=doAdd")public String doAdd(User user){System.out.println(user.getName());userService.addUser(user);return "redirect:user.htm?op=list";}}

读书人网 >VC/MFC

热点推荐