mybatis框架oracle和mysql数据分页查询语句

第一种: 用mybatis分页查询(oracle)这种一定要注意特殊符号,需要转换

    这是在网上查询到的资料,原路径:https://www.cnblogs.com/hq233/p/6753712.html

首先当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序错误。

  这样的问题在mBatiS中或者自定义的xml处理sql的程序中经常需要我们来处理。其实很简单,我们只需作如下替换即可避免上述的错误:

原符号 < <=  >>= &' "
替换符号&lt;&lt;=&gt;&gt;=&amp;&apos;&quot;
 

例如: 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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值