当前位置:Gxlcms > html代码 > springmvc+mybatis做分页的实例代码

springmvc+mybatis做分页的实例代码

时间:2021-07-01 10:21:17 帮助过:31人阅读

springmvc+mybatis 做分页sql 语句,代码如下:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="ssmy.dao.UserDao">
  6. <resultMap type="ssmy.dto.User" id="User">
  7. <!--<resultMap type="User" id="User"> 如果在sprin文件里配置初始化 mybatis里配置了别名就是有-->
  8. <!-- 用id属性来映射主键字段 -->
  9. <id property="id" column="id" jdbcType="INTEGER"/>
  10. <!-- 用result属性来映射非主键字段 -->
  11. <result property="userName" column="userName" jdbcType="VARCHAR"/>
  12. <result property="password" column="password" jdbcType="VARCHAR"/>
  13. <result property="trueName" column="trueName" jdbcType="VARCHAR"/>
  14. <result property="email" column="email" jdbcType="VARCHAR"/>
  15. <result property="phone" column="phone" jdbcType="VARCHAR"/>
  16. <result property="roleName" column="roleName" jdbcType="VARCHAR"/>
  17. </resultMap>
  18. <!--分页返回类型list 可以使用map User对应的是resultMap size每页的大小-->
  19. <select id="find" resultMap="User" parameterType="Map">
  20. select t2.* from
  21. ( select t1.*,rownum rn from t_user t1
  22. <where>
  23. <if test ="userName !=null and userName !='' ">
  24. t1.userName like '%'||#{userName,jdbcType=VARCHAR}||'%'
  25. </if>
  26. </where>
  27. ) t2
  28. <where>
  29. <if test ="start !=null and start !=''">
  30. <![CDATA[and t2.rn >=#{start}]]>
  31. </if>
  32. <if test ="size !=null and size !=''">
  33. and <![CDATA[t2.rn <=#{size}]]>
  34. </if>
  35. </where>
  36. </select>
  37. <!--获取总记录数 -->
  38. <select id="getTotal" parameterType="Map" resultType="java.lang.Integer">
  39. select count(1) from t_user
  40. <where>
  41. <if test ="userName !=null and userName !='' ">
  42. userName like '%'||#{userName,jdbcType=VARCHAR}||'%'
  43. </if>
  44. </where>
  45. </select>
  46. <!--<insert id="createser" parameterType="User">
  47. insert into NEWS_USER (id,username,password,email,usertype)
  48. values (#{id,jdbcType=NUMERIC},#{username,jdbcType=VARCHAR},
  49. #{password,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR},1)
  50. <selectKey resultType="int" order="BEFORE" keyProperty="id">
  51. select seq_id.nextval from dual
  52. </selectKey>
  53. </insert>-->
  54. </mapper>

以上就是springmvc+mybatis 做分页的实例代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行