利用MyBatis <if test>,实现简单表格的条件查询
数据库构建字段:
前端查询项:
初始查询,first_name,last_name,create_time
1.Dao层
@Select({“<script>"+"select" +"id",+"first_name"+"last_name"+"create_time",
"from tb_test",
"where create_time>= #{startDate}”
"and create_time<![CDATA[<=]]>#{endDate}",
"<if test ='first_name!=null and first_name!=\"\" '>",
"and first_name=#{firstName}",
"</if>",
"<if test ='last_name!=null and last_name!=\"\" '>",
"and last_name=#{lastName}",
"</if>",
“</script>"
})
2.前端
在查询框对应的字段绑定v-model及prop,即可实现条件查询