mybatis time interval comparison

mybatis time interval comparison

 

jdbcType=TIMESTAMP, jdbcType=DATE determines the format of the time
Some functions are not available in different versions of mysql
Note that the date type is passed in   < if test ="empId != null and empId != '' " >
AND o.EMP_ID = ${empId}
</if>
You can't have a comparison with strings like and empId != '', unless you pass in a type designed for string
 ### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util. Date and java.lang.String 
### Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String] with root cause

java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
at org.apache.ibatis.ognl.OgnlOps.compareWithConversion(OgnlOps.java:93)
at org.apache.ibatis.ognl.OgnlOps.isEqual( OgnlOps.java:143 )
at org.apache.ibatis .ognl.OgnlOps.equal(OgnlOps.java:802)
at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:53)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:61)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
。。。。
<![CDATA[    ]]> just escapes the special symbol < >

Go directly to the code, the Date type used by the database at this time: (ie: database type date, incoming is string)

copy code
    <if test="minCreateTime != null and  minCreateTime != ''">
            <![CDATA[ and g.create_time >= to_date(#{minCreateTime,jdbcType=DATE},'yyyy-MM-dd hh24:mi:ss')]]>
        </if>
        <if test="maxCreateTime != null and  maxCreateTime != ''">
            <![CDATA[ and g.create_time <= to_date(#{maxCreateTime,jdbcType=DATE},'yyyy-MM-dd hh24:mi:ss')]]>
        </if>
copy code

If it is a string type, it can also be compared directly, as follows: (date is passed in, any type of database)

copy code
       <if test="createTime != null">
                AND CREATE_TIME = CONCAT(CONCAT('%', #{createTime,jdbcType=DATE}), '%')
            </if>
            <if test="updateTime != null">
                AND UPDATE_TIME = CONCAT(CONCAT('%', #{updateTime,jdbcType=DATE}), '%')
            </if>
copy code

 

 

<if test="minCreateTime != null and  minCreateTime != ''">
            <![CDATA[ and g.create_time >= to_date(#{minCreateTime,jdbcType=DATE},'yyyy-MM-dd hh24:mi:ss')]]>
        </if>
        <if test="maxCreateTime != null and  maxCreateTime != ''">
            <![CDATA[ and g.create_time <= to_date(#{maxCreateTime,jdbcType=DATE},'yyyy-MM-dd hh24:mi:ss')]]>
        </if>

业务驱动技术,技术是手段,业务是目的。
 
 
 
 
<if test="(prassignTime != null )" >
  <![CDATA[ and o.ASSIGN_TIME  >= #{prassignTime,jdbcType=TIMESTAMP} ]]>
</if>
<if test="(lsassignTime != null)" >
  <![CDATA[ and o.ASSIGN_TIME <= #{lsassignTime,jdbcType=TIMESTAMP} ]]>
</if>
<if test="(prfirstdailTime != null ) " >
  <![CDATA[ and o.FIRSTDAIL_TIME  >= #{prfirstdailTime,jdbcType=TIMESTAMP} ]]>
</if>
<if test=" (lsfirstdailTime != null)" >
  <![CDATA[ and o.FIRSTDAIL_TIME  <= #{lsfirstdailTime,jdbcType=TIMESTAMP} ]]>
</if>
<if test="status != null and status != ''" >
  AND o.STATUS = ${status}
</if>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070096&siteId=291194637