草庐IT

bindingResult

全部标签

java - 带有 BindingResult 的 @Valid JSON 请求导致 IllegalStateException

我有一个接受JSON请求的REST服务。我想验证传入的JSON请求值。我该怎么做?在Spring3.1.0RELEASE中,我知道有人想确保他们使用的是3.1.13NewHandlerMethod-basedSupportClassesForAnnotatedControllerProcessing中列出的最新支持类。旧的是这样的项目:AnnotationMethodHandlerAdapter.我想确保我使用的是最新的,例如RequestMappingHandlerAdapter.这是因为我希望它能解决我看到的问题:java.lang.IllegalStateException:Er

java - Spring - 将 BindingResult 添加到新创建的模型属性

我的任务是-通过给定的请求参数创建模型属性,验证它(以相同的方法)并将其全部提供给View。我得到了这个示例代码:@ControllerclassPromotionController{@RequestMapping("promo")publicStringshowPromotion(@RequestParamStringsomeRequestParam,Modelmodel){//CreatethemodelattributebyrequestparametersPromotionpromotion=Promotions.get(someRequestParam);//Addthea

java - 将 JSR-303 验证错误转换为 Spring 的 BindingResult

我在SpringController中有以下代码:@Autowiredprivatejavax.validation.Validatorvalidator;@RequestMapping(value="/submit",method=RequestMethod.POST)publicStringsubmitForm(CustomFormform){Set>errors=validator.validate(form);...}是否可以将errors映射到Spring的BindingResult对象,而无需手动检查所有错误并将它们添加到BindingResult?像这样的://NOTE:

spring - 通过 RedirectionAttributes 传递 BindingResult

我试图通过RedirectionAttributes传递BindingResult:我已引用Spring-RedirectafterPOST(evenwithvalidationerrors),但还是卡住了。我有一个GET方法:@RequestMapping(value="/test",method=RequestMethod.GET)publicStringtest(@ModelAttribute("exampleForm")finalExampleFormexampleForm,finalModelmodel){return"test";}还有一个POST方法:@RequestMa

java - Errors/BindingResult 参数应在模型属性、@RequestBody 或 @RequestPart 参数之后立即声明

我通过剖析示例应用程序来自学Spring,然后在这里和那里添加代码来测试我在剖析过程中开发的理论。在测试我添加到Spring应用程序的一些代码时,我收到以下错误消息:AnErrors/BindingResultargumentisexpectedtobedeclaredimmediatelyafterthemodelattribute,the@RequestBodyorthe@RequestPartargumentstowhichtheyapply错误信息所指的方法是:@RequestMapping(value="/catowners",method=RequestMethod.GET

java - 什么原因导致 "java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ' 命令'可用作请求属性”?

这是针对这些类型问题的广泛规范问答帖子。我正在尝试编写一个SpringMVCWeb应用程序,用户可以在其中将电影名称添加到内存集合中。它是这样配置的publicclassApplicationextendsAbstractAnnotationConfigDispatcherServletInitializer{protectedClass[]getRootConfigClasses(){returnnewClass[]{};}protectedClass[]getServletConfigClasses(){returnnewClass[]{SpringServletConfig.cl

java - 如何从 BindingResult 获取 Controller 中的错误文本

我有一个返回JSON的Controller。它采用一个表单,通过spring注释验证自己。我可以从BindingResult获取FieldError列表,但它们不包含JSP将在标记中显示的文本。如何获取错误文本以JSON格式发回?@RequestMapping(method=RequestMethod.POST)public@ResponseBodyJSONResponsesubmit(@ValidAnswerFormanswerForm,BindingResultresult,Modelmodel,HttpServletRequestrequest,HttpServletRespon
12