时间: 2020-11-26|54次围观|0 条评论

一、发现问题

  <select id="count" resultType="java.lang.Integer" parameterType="java.lang.String"  >
     select count(*) from user
 
     <if test = "searchname!=null and searchname!='' ">
        where name like CONCAT('%',#{searchname},'%')
    </if>
  </select>

Mybatis查询传入一个字符串传参数,报There is no getter for property named 'searchname' in 'class java.lang.String'。

二、解决问题

在 mapper中加入注解

    int count(@Param(value="searchname")String searchname);

三、原因分析
Mybatis默认采用ONGL解析参数,所以会自动采用对象树的形式取string.num值,引起报错。也可以public int count (@Param(value=searchname) String searchname)的方法说明参数值

参考博客:
http://blog.sina.com.cn/s/blog_86e49b8f010191hw.html
http://txin0814.iteye.com/blog/1533645

原文链接:https://blog.csdn.net/w605283073/article/details/50846385

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《Mybatis中传参报There is no getter for property name ‘xxx’
   

还没有人抢沙发呢~