MyBatis - No constructor found

后端 未结 3 362
清歌不尽
清歌不尽 2021-01-19 23:06

I have a problem with MyBatis mapping. I have a domain class like this:

public class MyClass
{
   private Long id;
   private Date create;
   private String          


        
相关标签:
3条回答
  • 2021-01-19 23:53

    Just completing the answer of @Kazuki Shimizu.

    If you want to use the primitive type long instead of the wrapper Long in the constructor you need to change the binding to:

    @ConstructorArgs({
       @Arg(column = "id", javaType = long.class)
       ,@Arg(column = "create", javaType = Date.class)
       ,@Arg(column = "content", javaType = String.class)
    })
    
    0 讨论(0)
  • 2021-01-20 00:00

    You can use the @ConstructorArgs instead as follows:

    @ConstructorArgs({
        @Arg(column = "id", javaType = Long.class)
        ,@Arg(column = "create", javaType = Date.class)
        ,@Arg(column = "content", javaType = String.class)
    })
    
    0 讨论(0)
  • 2021-01-20 00:02

    MyBatis expects your model objects to have a no-arguments constructor (and possibly setters for each mapped field). Add those and everything should work.

    0 讨论(0)
提交回复
热议问题