先说一个自己总能碰见的问题,今天终于解决 在Test(测试类)中,引@Test有时会报错,
大多数是因为复制过来的代码所以造成这种原因,这个时候你肯定想到的是pom.xml,里面jar包没有引入,
可是如果引入了还报错是为什么呢,这是因为,你的XXX.iml里面没有加上这些
下面是智能标签:<!--智能标签foreach List自定义--> <select id="findByListGeneric" resultType="Student"> select <include refid="columns"></include> from student <if test="list.size>0"> WHERE stuno in <foreach collection="list" open="(" close=")" separator="," item="myitem"> #{myitem.stuno} </foreach> </if> </select> <!--智能标签foreach List--> <select id="findByList" resultType="Student"> select * from student <if test="list.size>0"> WHERE stuno in <foreach collection="list" open="(" close=")" separator="," item="myid"> #{myid} </foreach> </if> </select> <!--智能标签foreach--> <select id="findByArray" resultType="Student"> select * from student <if test="array.length>0"> WHERE stuno in <foreach collection="array" open="(" close=")" separator="," item="myid"> #{myid} </foreach> </if> </select> <!--智能标签choose--> <select id="findByChoose" resultType="Student"> select * from student <where> <choose> <when test="stuname != null"> and stuname like '%' #{stuname} '%' </when> <when test="stuage!=null"> and stuage>#{stuage} </when> <otherwise> and 1=1 </otherwise> </choose> </where> </select> <!--智能标签if--> <select id="findByIf" resultType="Student"> select * from student <where> <if test="stuname!=null"> and stuname like '%' #{stuname} '%' </if> <if test="stuage!=null"> and stuage>#{stuage} </if> </where> </select>
下面是一对多:
<resultMap id="DeptMapperMultipleSQL" type="Dept"> <id column="deptNo" property="deptNo"></id> <result column="deptName" property="deptName"></result> <collection property="emps" ofType="Emp" select="selectEmpsById" column="deptno"> </collection> </resultMap> <select id="selectEmpsById" resultType="Emp"> select * from emp where deptno=#{deptNo} </select> <!--一对多的单条SQL解决方案--> <select id="findEmpsByDeptNoMultipleSQL" resultMap="DeptMapperMultipleSQL"> select deptName,deptNo from dept where deptno=#{deptNo} </select> <resultMap id="DeptMapper" type="Dept"> <id column="deptNo" property="deptNo"></id> <result column="deptName" property="deptName"></result> <!-- ofType:集合中单个元素的类型 --> <collection property="emps" ofType="Emp"> <id column="empNo" property="empNo"></id> <result column="empName" property="empName"></result> </collection> </resultMap> <select id="findEmpsByDeptNo" resultMap="DeptMapper"> select empNo,empName,deptName,dept.deptNo from emp,dept where emp.deptno=dept.deptno and dept.deptno=#{deptNo} </select>
MyBatis--智能标签
最新推荐文章于 2022-11-01 10:32:55 发布