ssm框架查询数据并实现分页功能示例

26 篇文章 0 订阅

    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
  * DataGrid对象
  *
  */
@SuppressWarnings ( "rawtypes" )
public  class  DataGrid {
     private  int  total =  0 ;
     private  List rows =  new  ArrayList();
     public  int  getTotal() {
         return  total; //数据总数
     }
     public  void  setTotal( int  total) {
         this .total = total;
     }
     public  List getRows() {
         return  rows; //页面显示的数据
     }
     public  void  setRows(List rows) {
         this .rows = rows;
     }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public  class  UserInfoDO {
     private  String userName; // 用户姓名
     private  String phoneNum; //用户电话
     private  String identityNum; //卡号
     private  String plStatus; //插件状态
     private  int  startNum; //分页-起始数
     public  String getUserName() {
         return  userName;
     }
     public  void  setUserName(String userName) {
         this .userName = userName;
     }
     public  String getPhoneNum() {
         return  phoneNum;
     }
     public  void  setPhoneNum(String phoneNum) {
         this .phoneNum = phoneNum;
     }
     public  String getIdentityNum() {
         return  identityNum;
     }
     public  void  setIdentityNum(String identityNum) {
         this .identityNum = identityNum;
     }
     public  String getPlStatus() {
         return  plStatus;
     }
     public  void  setPlStatus(String plStatus) {
         this .plStatus = plStatus;
     }
     public  int  getStartNum() {
         return  startNum;
     }
     public  void  setStartNum( int  startNum) {
         this .startNum = startNum;
     }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public  class  UserInfoController {
     @Autowired
     private  UserInfoService userInfoService;
     /**
      * 查询
      *
      * @return
      */
     @RequestMapping (value =  "/userInfo.do" , method = RequestMethod.POST)
     @ResponseBody
     public  String getList( @RequestBody  UserInfoDO userInfoDo, HttpServletRequest request, HttpServletResponse response) {
         JSONObject jsonObject =  new  JSONObject();
         try  {
             DataGrid dataGrid = userInfoService.getUserInfo(userInfoDo);
             jsonObject = JSONObject.fromObject(dataGrid);
         catch  (Exception e) {
             e.printStackTrace();
         }
         return  jsonObject.toString();
         }
}

  

1
2
3
public  interface  UserInfoService {
     public  DataGrid getUserInfo(UserInfoDO userInfoDo)  throws  SQLException;
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Service
public  class  SignLogServiceImpl  implements  SignLogService {
     @Resource
     private  SignLogDao signLogDao;
     @Override
     public  DataGrid getSignLog(SignLogDO signLogDo)  throws  SQLException {
         DataGrid grid =  new  DataGrid();
         List<SignLogDO> signLogList =  null ;
         try  {
             signLogList = signLogDao.getSignLog(signLogDo);
             grid.setTotal(signLogDao.getTotalNum(signLogDo));
             grid.setRows(signLogList);
         }
         catch  (Exception e) {
         e.printStackTrace();
         }
         return  grid;
     }
}

  

1
2
3
4
5
6
7
public  interface  UserInfoDao {
 
     public  List<UserInfoDO> getUserInfo(UserInfoDO userInfoDo)  throws  SQLException;
 
     public  int  getTotalNum(UserInfoDO userInfoDo)  throws  SQLException;
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Repository
public  class  UserInfoDaoImpl  extends  SqlSessionDaoSupport  implements  UserInfoDao{
     @Resource
     public  void  setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
         super .setSqlSessionFactory(sqlSessionFactory);
     }
     @Override
     public  List<UserInfoDO> getUserInfo(UserInfoDO userInfoDo)  throws  SQLException {
         return  this .getSqlSession().selectList( "userInfoDO.getUserInfo" ,userInfoDo);
     }
     @Override
     public  int  getTotalNum(UserInfoDO userInfoDo)  throws  SQLException {
         return  this .getSqlSession().selectOne( "userInfoDO.getTotalNum" ,userInfoDo);
     }
}

  

复制代码
<mapper namespace="userInfoDO">
    <resultMap id="BaseResultMap" type="UserInfoDO">
        <result column="phone_num" property="phoneNum" jdbcType="VARCHAR"/>
        <result column="user_name" property="userName" jdbcType="VARCHAR"/>
        <result column="identity_num" property="identityNum" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="getUserInfo" resultMap="BaseResultMap" parameterType="UserInfoDO">
        select phone_num,user_name,identity_num from tb_user 
        <where>
            <if test="phoneNum!=null and phoneNum!=''">
                phone_num like '%${phoneNum}%'
            </if>
            <if test="userName != '' and userName != null" >
                and user_name like '%${userName}%'
            </if>
            <if test="identityNum != '' and identityNum != null" >
                and identity_num like '%${identityNum}%'
            </if>
         </where>
         limit #{startNum},5 //每页五条数据
    </select>
    
    <select id="getTotalNum" resultType="int" parameterType="UserInfoDO">
        select count(*) from tb_user 
        <where>
            <if test="phoneNum!=null and phoneNum!=''">
                phone_num like '%${phoneNum}%'
            </if>
            <if test="userName != '' and userName != null" >
                and user_name like '%${userName}%'
            </if>
            <if test="identityNum != '' and identityNum != null" >
                and identity_num like '%${identityNum}%'
            </if>
         </where>
    </select>  
</mapper>
复制代码

 

  




转载网址:http://www.cnblogs.com/li--xin/p/6216068.html

相关阅读:SSM框架——实现分页和搜索分页

网址:http://blog.csdn.net/zhshulin/article/details/26447713




  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值