mybatis中小于号没有办法直接写

  • 方式一需要使用特殊转义字符:
 <

例子

<select id="selectRolesPage" parameterType="java.util.Map" resultType="com.leilankeji.cn.dao.SysRole" >
    select
    *
    from t_sys_role
    <where>
      <if test="roleName != null and roleName != ''">
      and role_name like  concat('%',#{roleName},'%')
    </if>
      <if test="beginTime">
        and create_time >= #{beginTime}
      </if>
      <if test="endTime">
        and create_time &lt;= #{endTime}
      </if>
      <if test="status!= null">
        and status = #{status}
      </if>
    </where>

  </select>
  • 方式二 使用 <![CDATA[ ?]]> 符号
    ?代表的是需要不想被解析的文本
  <select id="selectRolesPage" parameterType="java.util.Map" resultType="com.leilankeji.cn.dao.SysRole" >
    select
    *
    from t_sys_role
    <where>
      <if test="roleName != null and roleName != ''">
      and role_name like  concat('%',#{roleName},'%')
    </if>
      <if test="beginTime">
        and create_time >= #{beginTime}
      </if>
<!--      <if test="endTime">-->
<!--        and create_time &lt;= #{endTime}-->
<!--      </if>-->
      <if test="endTime">
        and create_time <![CDATA[<=]]> #{endTime}
      </if>
      <if test="status!= null">
        and status = #{status}
      </if>
    </where>

  </select>
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐