第一种: 用mybatis分页查询(oracle)这种一定要注意特殊符号,需要转换
这是在网上查询到的资料,原路径:https://www.cnblogs.com/hq233/p/6753712.html
首先当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序错误。
这样的问题在mBatiS中或者自定义的xml处理sql的程序中经常需要我们来处理。其实很简单,我们只需作如下替换即可避免上述的错误:
原符号 | < | <= | > | >= | & | ' | " |
替换符号 | < | <= | > | >= | & | ' | " |
例如: from为从哪条记录开始,pageSize为每页显示的条数
<select id="getProductType2" resultType="com.crm.model.ProductType">
select id,pid,fcode,code,name,remark,sort,create_time as createTime
from (select t.*, rownum rn
from (select *
from b_product_type
order by id asc )t
where rownum <= #{pageSize}) where 1=1 and rn>#{from}
<if test="productType.name!=null and productType.name!=''" >
and name like concat('%',#{productType.name},'%')
</if>
<if test="productType.code!=null and productType.code!=''">
and code like concat('%',#{productType.code},'%')
</if>
limit #{from},#{pageSize}
</select>
第二种:在mysql数据库用mybatis如何和进行分页
<select id="getProductType2" resultType="com.crm.model.ProductType">
select id,pid,fcode,code,name,remark,sort,create_time as createTime
from b_product_type where 1=1
<if test="productType.name!=null and productType.name!=''" >
and name like concat('%',#{productType.name},'%')
</if>
<if test="productType.code!=null and productType.code!=''">
and code like concat('%',#{productType.code},'%')
</if>
limit #{from},#{pageSize}
</select>