Mybatis——动态SQL语句!
含义 动态的SQL语句,就是指在运行的时候,根据Mapper.xml中的语句,来决定方法传入参数的使用。 使用 <if test=""></if>标签 Mapper.xml中的配置 if 判断 参数传入的值,判断是否可以使用,再执行SQL语句, 缺点 如何传入的值分别是null,1时or 符号不会消失,这样sql语句识别不出来。 < select id = "queryUserByUser" resultType = "com.atguigu.pojo.User" parameterType = "com.atguigu.pojo.User" > select `id` , `last_name` lastName , `sex` from t_user where < if test = "lastName!=null" > last_name = # { lastName } < / if > < if test = "sex==0||sex==1" > or sex = # { sex } < / if > < / select > <where ></where>标签 Mapper.xml中的配置where能有效帮助我们,添加和去除查询条件 前面 的关键字。 缺点 不能去除查询条件 后面 的多余的关键。 < select id = "queryUserByUser"