mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.String'

在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter 来代替参数名。

正确的写法:

[html] view plaincopyprint?

  1. <span style="font-size:18px;">    <!-- 用于查询运单号是否存在 -->
  2. <select id="isCargoBillNoExist" resultType="java.lang.Integer">
  3. select count(1)
  4. from t_entry_cargo_receiver_info
  5. where 1=1
  6. <if test="_parameter != null" >
  7. and cargo_bill_no = #{<span style="color:#ff0000;">_parameter</span>,jdbcType=VARCHAR}
  8. </if>
  9. </select></span>

错误的写法:

[html] view plaincopyprint?

  1. <span style="font-size:18px;">    <!-- 用于查询运单号是否存在 -->
  2. <select id="isCargoBillNoExist" resultType="java.lang.Integer">
  3. select count(1)
  4. from t_entry_cargo_receiver_info
  5. where 1=1
  6. <if test="id != null" >
  7. and cargo_bill_no = #{<span style="color:#ff0000;">id</span>,jdbcType=VARCHAR}
  8. </if>
  9. </select></span>

评论区有人提到:

也可以在mapper的接口中,给这个方法的参数加上@param(value=“id”),这样就能在.xml中使用#{id,jdbcType=VARCHAR} 了。

这样也是可以的。

===============分割线===============

不过本文提到的错误,在实践中发现,并不都会出现。可能跟mybatis的版本有关系,就是说按照上文"错误"的写法来写,在某些版本中也是没有问题的,不必纠结。

如果出现了标题的错误,按照文中的方式解决即可。

mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.String'

时间: 2024-08-06 16:03:50

mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.String'的相关文章

mybaits错误解决:There is no getter for property named &#39;id&#39; in class &#39;java.lang.String&#39;(转)

在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter来代替参数名. 正确的写法: [html] view plain <span style="font-size:18px;">    <!-- 用于查询运单号是否存在 --> <select id="isCargoBillNoExist" resultType="java.lang.Integer&quo

错误解决:There is no getter for property named &#39;id&#39; in class &#39;java.lang.String&#39;

使用mybatis传入参数,如果在mappin.xml中使用<if>标签判断该参数是否为空,通常会报以上异常,解决方法:?在接口中该方法的参数前加上@Param("参数名")注解,即可? 错误解决:There is no getter for property named 'id' in class 'java.lang.String' 原文地址:https://www.cnblogs.com/lqh969696/p/11578492.html

关于mybtis 使用过程中发生There is no getter for property named &#39;id&#39; in class &#39;java.lang.String&#39; 错误

今天在修改一个关于mybtis语句时,偶然发现的一个错误  There is no getter for property named 'id' in class 'java.lang.String', 纠结了许久,终于明白了为什么. 原因:Mybatis默认采用ONGL解析参数,所以会自动采用对象树的形式取 string.xxx 值,如果没在在方法中定义,则会抛异常报错.当然也不是所有的版本会有这个问题,我的项目用的版本比较老. 有两种解决方案: 方案一: 将对应的参数用 _parameter

There is no getter for property named &#39;id&#39; in class &#39;java.lang.String&#39;

https://blog.csdn.net/u011897392/article/details/46738747 使用mybatis传入参数,如果在mappin.xml中使用<if>标签判断该参数是否为空,通常会报以上异常,解决方法:?在接口中该方法的参数前加上@Param("参数名")注解,即可? 接口: public interface UserMapper { //根据名称查询用户 List<MAP> queryUserByName(@Param(&qu

There is no getter for property named &#39;userId&#39; in &#39;class java.lang.String&#39;

[ERROR] 2017-01-18 04:37:06:231 cn.dataenergy.common.CenterHandlerExceptionResolver (CenterHandlerExceptionResolver.java:44) - 统一捕获异常: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Th

Mybatis问题:There is no getter for property named &#39;unitId&#39; in &#39;class java.lang.String&#39;

Mybatis遇到的问题 问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'unitId' in 'class java.lang.String' at org.mybatis.spring.MyBatisExceptionTransla

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;zoneId&#39; in &#39;class java.lang.String&#39;

本文为博主原创,未经允许不得而转载: 异常展示: dao层定义的接口为: public int getClientTotal(); 在mybatis中的sql为: <select id="getClientTotal" parameterType="String" resultType="Integer"> SELECT COUNT(*) AS oldNum FROM tbl__client_info <where> &l

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;parentId&#39; in &#39;class java.lang.String&#39;

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:333) at org.apache.ibatis.reflection.Meta

MyBatis3: There is no getter for property named &#39;code&#39; in &#39;class java.lang.String&#39;

mybatis3  : mysql文如下,传入参数为string类型时‘preCode’,运行报错为:There is no getter for property named 'preCode' in 'class java.lang.String 执行sql: mapper.xml文件: <select id="getMaxCode" parameterType="string" resultType="string"> sele