Select Tag with Object - Thymeleaf and Spring MVC

后端 未结 2 1846
梦如初夏
梦如初夏 2021-01-02 14:21

I\'m trying to change the code of this example thymeleafexamples-stsm, so I changed enum type for class type:

Type.java

public class Type { 

    p         


        
2条回答
  •  灰色年华
    2021-01-02 14:53

    That error message basically says Spring don't know how to convert the string thymeleafexamples.stsm.business.entities.Type@2c08cec0 into an instance of Type. This is a bug on your code because it doesn't make any sense trying to do so.

    You're not supposed to use the toString() value of Object as a form dropdown identifier. You need to have a (much) better strategy for the code to identify the Type selected by user.

    Common approach is to use the id attribute:

    
    

    When the form is submitted, you then need to retireve an instance of Type based on its id name on your controller

提交回复
热议问题