相关疑难解决方法(0)

如何在表单验证失败时提供我选择的消息

我正在使用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)

validation spring-mvc

3
推荐指数
1
解决办法
4102
查看次数

标签 统计

spring-mvc ×1

validation ×1