Mybatis单个参数的if判断(针对异常:There is no getter for property..)
来源:互联网 发布:java yield join 编辑:程序博客网 时间:2024/06/08 14:42
我们都知道mybatis在进行参数判断的时候,直接可以用 就可以了,如下:
1、常规代码
<update id="update" parametertype="com.cq2022.zago.order.entity.Test"> update t_test_l <set> <if test="trnsctWayId != null"> trnsct_way_id = #{trnsctWayId,jdbcType=TINYINT}, </if> <if test="langId != null"> lang_id = #{langId,jdbcType=INTEGER}, </if> </set> where trnsct_way_l_id = #{trnsctWayLId,jdbcType=INTEGER} </update>
但是单个参数和多参数的判断有个不同点,当我们的入参为entity实体,或者map的时候,使用if 参数判断没任何问题。
但是当我们的入参为java.lang.Integer 或者 java.lang.String的时候,这时候就需要注意一些事情了
具体代码如下(咱们看着代码说,先展示错误代码):
2、错误代码
<select id="getTrnsctListByLangId" parameterType="java.lang.Integer" resultType="java.lang.Integer"> select trnsct_id from t_trnsct_way_l where <if test="langId != null" > and lang_id = #{langId} </if> </select>上述代码存在一些问题,首先入参是java.lang.Integer, 而不是map或者实体的入参方式,对于这类单个入参然后用if判断的,mybatis有自己的内置对象,
如果你在if判断里面 写的是你的入参的对象名,那就报异常:Internal error : nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'langId' in 'class java.lang.Integer'
3、正确代码:
<select id="searchAllCommodity" resultMap="categoryResultMap" parameterType="String"> SELECT C.category_name categoryName, A.user_business_id id, D.name name, D.logo imageUrl FROM user_business A LEFT JOIN user_business_category B ON B.business_id = A.user_business_id LEFT JOIN service_category C ON C.category_id = B.category_one_id LEFT JOIN user_business_commodity D ON D.user_business_id = A.user_business_id <where> <if test="_parameter !=null and _parameter !=''"> AND C.category_name = #{categoryName,jdbcType=String} </if> AND B.is_delete = 0 AND A.is_delete = 0 AND C.is_delete = 0 </where> </select>这里就涉及到mybatis的内置对象_parameter,单个参数判断的时候,就不像1、 2那样直接用参数对象名判断了。还有就是数据类型最好加上
阅读全文
0 0
- Mybatis单个参数的if判断(针对异常:There is no getter for property..)
- Mybatis 单个参数的if判断(针对异常:There is no getter for property..)
- Mybatis单个参数的if判断(针对异常:There is no getter for property..)
- 使用MyBatis数组参数出现异常There is no getter for property named '__frch_customId_0'
- mybatis存入String类型参数报There is no getter for property异常
- mybatis 基本类型的if条件判断问题 There is no getter for property named 'xxx' in 'class Java.lang.Integer'
- Mybatis中传参报There is no getter for property name 'xxx'
- Mybatis:There is no getter for property named XXX
- Mybatis There is no getter for property named 'id'
- mybatis 异常:There is no getter for property named 'classId' in 'class java.lang.Integer'
- Mybatis-异常-There is no getter for property named 'VARCHAR' in 'class com.xxx.xxxxx
- mybatis 异常信息 org.apache.ibatis.reflection.ReflectionException: There is no getter for property named
- Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String
- 当传入数据只有一个时mybatis中<if>判断会出现There is no getter for property named 'subjectId' in 'class java.lang....
- Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String' Mybatis版本:mybatis-
- 关于Mybatis 的 There is no getter for property named 错误
- 关于Mybatis的There is no getter for property named 'xxxx '错误
- Mybatis ReflectionException:There is no getter for property named 遇到的问题小结
- fabric.js自定义字体的引入
- CentOS 7.3下安装MySQL 5.7
- Python的BeautifulSoup之find和find_all
- 小白的Python之路——初识Python
- MySQL多表查询
- Mybatis单个参数的if判断(针对异常:There is no getter for property..)
- 马里奥吃金币消失
- Unity Profiler 性能分析
- Kafka Java 牛刀小试
- C语言实现直方图统计和直方图均衡化
- android studio 3.0 升级问题,遇到的坑;
- 文章标题
- 2018,中国区块链将引爆硅谷
- Maven项目,无法显示src/main/java资源文件夹