在选择语句where后面添加1=1与其他选择条件做连接操作
先在sql选择语句where后面添加1=1(1=1都知道是绝对能够匹配的条件)这个查询条件,再在后面做连接每个字符串前面添加and/or,这样无论进行何种查询,结果都不会报错,可以说是比较简便的方法了。具体操作示例如下:
sql语句定义(使用xml文件)
前三种
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.StudentMapper">
<resultMap id="sss" type="student">
<result property="id" column="id"/>
<result property="studentNo" column="studentNo"/>
<result property="loginPwd" column="loginPwd"/>
<result property="studentName" column="studentName"/>
<result property="sex" column="sex"/>
<result property="phone" column="phone"/>
<result property="address" column="address"/>
<result property="bornDate" co