代码之家  ›  专栏  ›  技术社区  ›  methuselah

Ibatis绑定异常错误消息

  •  2
  • methuselah  · 技术社区  · 6 年前

    我正在尝试实现以下ibatis插入注释,但始终收到以下错误消息:

    组织。阿帕奇。伊巴蒂斯。结合BindingException:参数“person”不是 建立可用参数有[arg1、arg0、param1、param2]

    这是我目前的代码。如何修复它?

    @(Insert("INSERT INTO profile (person, school) VALUES (#{person}, #{school})";)
    void insertOne(TestTextMessage person, String school)
    

    某些上下文:

    尝试此。。。 @(Insert("INSERT INTO profile (person, school) VALUES (#{arg0}, #{arg1})";) 但是得到一个java。lang.断言错误。TestTextMessage是一个包含以下值的类:

    @Data
    @NoArgs
    @EqualsAndHashCode
    public class TestTextMessage {
       private long id;
       private String name;
       private int age;
    }
    

    现在我这样称呼它:

    messageMapper.insertOne(new TestTextMessage(person1), SchoolType.EDENGLEN);
    

    如果我将学校类型移动到类中,那么它应该起作用,但如何为学校类型赋值?

    1 回复  |  直到 6 年前
        1
  •  5
  •   Dean Xu    6 年前

    使用 arg0 arg1

    @(Insert("INSERT INTO profile (person, school) VALUES (#{arg0}, #{arg1})")
    

    使用 @Param 为param命名。

    void insertOne(@Param("person")TestTextMessage person, @Param("school") String school)