Spring framework using validator after upgrade

24 views Asked by At

I am upgrading the spring framework from very old version to 5.3.9. In the current Spring configuration, I have below validation framework included. In the new spring, I will not have the below info in the configuration file. How can I replace with validation in the new Spring framework ?

<bean id="editAdmin" class="abc.controller.EditAdminController">
      <property name="sessionForm"><value>true</value></property>
      <property name="synchronizeOnSession"><value>true</value></property>
      <property name="commandName"><value>AdminClass</value></property>
      <property name="commandClass"><value>abc.bean.AdminClass</value></property>
      <property name="formView"><value>Admin</value></property>
      <property name="successView"><value>view_admin.html</value></property>
      **<property name="validator"><ref bean="adminValidator"/></property>**
      <property name="dao"><ref bean="adminDAO"/></property>
    </bean>

How do I invoke validation in the controller using new spring version ?

I found below sample online. I think it will work but haven't tried yet.

@RequestMapping(value = "/saveBasicInfoStep1", method = RequestMethod.POST) public String saveBasicInfoStep1(
@Validated(BasicInfo.class) @ModelAttribute("useraccount") UserAccount useraccount, BindingResult result, ModelMap model) { if (result.hasErrors()) { return "error"; } return "success"; }

Thanks!

0

There are 0 answers