数据库相关不区分大小写,类相关需要考虑大小写
动态sql
a.
<select id="queryStudentByNameOrAgeWithSQLTag" parameterType="student"
resultType="student">
select stuNo,stuName,stuAge from student where 1=1
<if test="stuName !=null and stuName!='' ">
and stuname=#{stuName}
</if>
<if test="stuAge !=null and stuAge!=0 ">
and stuage=#{stuAge}
</if>
</select>
1=1是为了后面可以跟and,防止有数字为空
b.
<select id="queryStudentByNameOrAgeWithSQLTag" parameterType="student"
resultType="student">
select stuNo,stuName,stuAge from student
<where>
<if test="stuName !=null and stuName!='' ">
stuname=#{stuName}
</if>
<if test="stuAge !=null and stuAge!=0 ">
and stuage=#{stuAge}
</if>
</where>
</select>
标签只能自动处理标签的第一个and
标签
ids={1,2,5}
select stuno,stuname from student where stuno in(1,2,5)
迭代的类型:数组、集合、属性(Grade类:List ids)
属性:Grade类:List ids
<select id="queryStudentWithNoswithGrade" parameterType="grade"
resultType="Student">
select * from student
<where>
<if test="stuNos!=null and stuNos.size>0">
<foreach collection="stuNos" open=" and stuno in(" close=")"
item="stuNo" separator="; ">
#{stuNo}
</foreach>
</if>
</where>
</select>
数组:
无论编写代码时,传递的时参数名必须用array代替该数组。
集合:
无论编写代码时,传递的时参数名必须用list代替该数组。