mybatis if标签判断的问题
<?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="com.lypaydb.mapper.Order_DayMapper">
<resultMap type="com.lypaydb.pojo.Order_Day" id="odMap">
<id property="id" column="id" />
<result property="date" column="date" />
<result property="total" column="total" />
<result property="aisle" column="aisle" />
<result property="operators" column="operators" />
<result property="channelid" column="channelid" />
<result property="appid" column="appid" />
<result property="paycnt" column="paycnt" />
</resultMap>
<!-- /*sql -->
<select id="findod" parameterType="java.util.Map" resultMap="odMap">
select * from order_day where 1 = 1
<if test="${start} != null and ${start != ''}">
and date >= #{start}
</if>
<if test="${end} != null and ${end} != ''">
and #{end} > date
</if>
<if test="appid != null and appid != ''">
and appid=${appid}
</if>
<if test="operators != null and operators != ''">
and operators=${operators}
</if>
limit ${Page.startPos},${Page.pageSize};
</select>
<select id="getAllCount" parameterType="java.util.Map" resultType="java.lang.Integer">
select count(*) from order_day where 1=1
<if test="${start} != null and ${start != ''}">
and date >= #{start}
</if>
<if test="${end} != null and ${end} != ''">
and #{end} > date
</if>
<if test="appid != null and appid != ''">
and appid=${appid}
</if>
<if test="operators != null and operators != ''">
and operators=${operators}
</if>
</select>
<!-- sql*/ -->
</mapper>
主要看我的findod方法里边的前两个if判断,由于我这个POJO类里边只有一个date,日期类型。我要传过来两个时间点供查询,我是放到一个map里边,key-value分别是("start",时间)和("end",时间)。
为什么报这个错
nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression '${start} != null and ${start != ''}'. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: ${start} != null and ${start != ''} [org.apache.ibatis.ognl.ParseException: Encountered "$" at line 1, column 1. Was expecting one of: ":" ... "not" ... "+" ... "-" ... "~" ... "!" ... "(" ... "true" ... "false" ... "null" ... "#this" ... "#root" ... "#" ... "[" ... "{" ... "@" ... "new" ... ... ... "\'" ... "`" ... "\"" ... ... ... ]
而我把start和end的条件判断去掉,下边两个条件都能正常使用,怎么解决啊?难道这个if判断的条件只能是POJO类里的属性么?求解答啊,在线等
...全文
相关推荐
Mybatis传单个参数和<if>标签同时使用的问题及解决方法
解决方法----------解决这个问题有两种方法:1.去掉if判断首先,我们可以直接去掉Mapper.xml文件中的if判断,直接使用where条件来检索数据,例如:<select id="selectByAlarmId
MyBatis 动态拼接Sql字符串的问题
**If标签**:MyBatis的`<if>`标签用于条件判断,它允许我们在SQL语句中根据Java对象的属性值动态添加或忽略某些部分。
Mybatis中动态SQL,if,where,foreach的使用教程详解
**if**标签: `if`标签用于在SQL语句中进行条件判断。例如,当传入的参数不为空时,才会将其拼接到SQL中。在上述例子中,我们看到`<if test="userCustom !
JavaGuide-MyBatis动态SQL实战教程
动态SQL的学习不仅仅限于官方提供的标签,还涉及到一些高级的使用技巧,比如如何利用动态SQL实现复杂的业务逻辑判断,如何优化SQL语句以提高性能,以及如何将动态SQL与MyBatis的缓存机制结合起来使用等
4-动态SQL语句编写.pdf
### 动态SQL标签#### 1. if标签if标签用于实现条件判断。在使用if标签时,可以设定一个test属性,该属性接受一个boolean表达式。


