org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderExce

使用mybaties的@SelectProvider时出现的问题

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error invoking SqlProvider method (com.example.demo.dynamicsql.SqlProvider.selectCandidate).  Cause: org.apache.ibatis.binding.BindingException: Parameter 'arg0' not found. Available parameters are [id, param1]

上面是抛出的异常,就是找不到参数,我首先要生成一个动态sql,id默认为0,如果id为0,就查出所有数据,即不拼接where条件,若id不为0就查处对应的一条数据。新建一个和dao文件夹同级的pakage,里面的代码如下


然后我的dao层,代码为

 @SelectProvider(type = SqlProvider.class, method = "selectCandidate")
    @Results(id="candidateMap",value={
            @Result(property="id", column="id"),
            @Result(property="job", column="job"),
            @Result(property="salary", column="salary"),
            @Result(property="interviewTime", column="interview_time"),
            @Result(property="channel", column="channel"),
            @Result(property="name", column="name"),
            @Result(property="sex", column="sex"),
            @Result(property="nativePlace", column="native_place"),
            @Result(property="edu", column="edu"),
            @Result(property="peoples", column="peoples"),
            @Result(property="birthday", column="birthday"),
            @Result(property="domicile", column="domicile"),
            @Result(property="marriage", column="marriage"),
            @Result(property="politicalStatus", column="political_status"),
            @Result(property="address", column="addtress"),
            @Result(property="workAge", column="work_age"),
            @Result(property="phone", column="phone"),
            @Result(property="contracts", column="contracts"),
            @Result(property="contactsPhone", column="contracts_phone"),
            @Result(property="email", column="email"),
            @Result(property="qq", column="qq"),
            @Result(property="education", column="education"),
            @Result(property="work", column="work"),
            @Result(property="certificate", column="certificate"),
            @Result(property="skill", column="skill"),
            @Result(property="state", column="state"),
    })
    List<Candidate> selectCandidate(@Param("id")Integer id);

然后当我在动态sql类SqlProvider里面打断点,就发现无论把断点打着函数的哪个位置,断点都进不来,我开始怀疑是不是我的动态sql使用姿势错了,https://www.cnblogs.com/he-px/p/7134524.html,查看了这篇博客,我发现前端即便是传一个参数,sql类函数的参数也是map,然后从map里面过去想要的条件参数,于是我把SqlProvider这里里面对应函数的参数改成map。


这样就可以,可是为什么para的大小是2呢,我们查看debug控制台


然后去Dao那一层,我们试着将@Param那个参数删掉,然后我SqlProvider还原到参数是integer的样子,结果成功解决

猜你喜欢

转载自blog.csdn.net/zhangludcsdn/article/details/79975704
今日推荐