您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

springmvc+mybatis 做分页的实例代码

2024/3/4 8:34:38发布24次查看
springmvc+mybatis 做分页sql 语句,代码如下:
<?xml version="1.0" encoding="utf-8" ?> <!doctype mapper public "-//mybatis.org//dtd mapper 3.0//en" "mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="ssmy.dao.userdao"> <resultmap type="ssmy.dto.user" id="user"> <!--<resultmap type="user" id="user"> 如果在sprin文件里配置初始化 mybatis里配置了别名就是有--> <!-- 用id属性来映射主键字段 --> <id property="id" column="id" jdbctype="integer"/> <!-- 用result属性来映射非主键字段 --> <result property="username" column="username" jdbctype="varchar"/> <result property="password" column="password" jdbctype="varchar"/> <result property="truename" column="truename" jdbctype="varchar"/> <result property="email" column="email" jdbctype="varchar"/> <result property="phone" column="phone" jdbctype="varchar"/> <result property="rolename" column="rolename" jdbctype="varchar"/> </resultmap> <!--分页返回类型list 可以使用map user对应的是resultmap size每页的大小--> <select id="find" resultmap="user" parametertype="map"> select t2.* from ( select t1.*,rownum rn from t_user t1 <where> <if test ="username !=null and username !='' "> t1.username like '%'||#{username,jdbctype=varchar}||'%' </if> </where> ) t2 <where> <if test ="start !=null and start !=''"> <![cdata[and t2.rn >=#{start}]]> </if> <if test ="size !=null and size !=''"> and <![cdata[t2.rn <=#{size}]]> </if> </where> </select> <!--获取总记录数 --> <select id="gettotal" parametertype="map" resulttype="java.lang.integer"> select count(1) from t_user <where> <if test ="username !=null and username !='' "> username like '%'||#{username,jdbctype=varchar}||'%' </if> </where> </select> <!--<insert id="createser" parametertype="user"> insert into news_user (id,username,password,email,usertype) values (#{id,jdbctype=numeric},#{username,jdbctype=varchar}, #{password,jdbctype=varchar},#{email,jdbctype=varchar},1) <selectkey resulttype="int" order="before" keyproperty="id"> select seq_id.nextval from dual </selectkey> </insert>--> </mapper>
以上就是springmvc+mybatis 做分页的实例代码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product