我正在使用spring mvc 3.0.这是我的控制器类:
@Controller
@RequestMapping("/author")
public class AuthorController {
@Autowired
private IAuthorDao authorDao;
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, true));
}
@RequestMapping(method = RequestMethod.GET)
public String get(Model model) {
return "author-list";
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String create(Model model) {
model.addAttribute("author", new Author());
return "author-form";
}
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String createPost(@ModelAttribute("author") Author author,
BindingResult result) {
new AuthorValidator().validate(author, result);
if (result.hasErrors()) {
return "author-form"; …
Run Code Online (Sandbox Code Playgroud)