简体   繁体   中英

Spring MVC Validation error

I have a Spring controller that accepts one of my business objects as an argument, that spring is automatically building from form data. One of the attributes of the object is an enum that comes from a select dropdown in the form. I am also using the @Valid notation to do validation on the object, using an implementation of the Spring Validator interface.

In testing, I manually added a selection to the dropdown (using the browser inspector) that is not valid, since it can't be converted to an enum. I would have thought that Spring would just leave the enum attribute as null, and the validator would catch the error, but I actually get a runtime error:

javax.el.ELException: Cannot convert CC of type class java.lang.String to class com.app.enums.States

Any ideas on how to handle this?

We need more details on what you want to happen when this occurs. You could tell Spring how to convert that String into an instance of States by using a Converter (see this page for details).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM