有时候开发中需要根据多个ID去查询,可以将ID封装为List或者数组然后使用MyBatis中的foreach标签构建in条件. 这里我将ID封装为String[]作为参数. <select id="selectList" parameterType="java.util.List" resultType="java.lang.Integer"> SELECT COUNT(1) FROM t_user WHERE id IN <f…
1.常见错误: There is no getter for property named 'parentId' in 'class java.lang.Long'(或者String) org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'paren…
Mybatis中生成动态SQL的标签有四类,分别是: if choose (when, otherwise) trim (where, set) foreach 1.if 当需要动态生成where条件时,可以使用if标签: <select id="findActiveBlogWithTitleLike" resultType="Blog"> SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <if test=&qu…
当 where 中的条件使用的 if 标签较多时,这样的组合可能会导致错误.当 java 代码按如下方法调用时: @Test public void select_test_where() { User user = new User(); user.setUsername(null); user.setSex(1); List<User> userList = this.dynamicSqlMapper.getUsertList_where(user); for (User u : user…
trim代替where/set标签 trim 是更灵活用来去处多余关键字的标签,它可以用来实现 where 和 set 的效果. <!-- 使用 if/trim 代替 where(判断参数) - 将 User 类不为空的属性作为 where 条件 --> <select id="getUsertList_if_trim" resultMap="resultMap_User"> SELECT * FROM user u <trim p…
<select id="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHERE <if test="state != null"> state = #{state} </if> <if test="title != null"> AND title like #{title} </if> &l…