ssm框架查询数据并实现分页功能示例
来源:互联网 发布:怎么看淘宝代购真假 编辑:程序博客网 时间:2024/04/29 17:57
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
阅读全文
0 1
- ssm框架查询数据并实现分页功能示例
- ssm实现分页查询
- SSM框架---实现分页
- ssm框架中的分页功能
- SSM框架集成PageHelper插件,实现分页功能
- SSM框架 用ajax实现模糊查询分页和列表
- datagrid+yii2实现数据查询分页功能
- 实现组合查询数据并分页显示
- Java SSM框架实现分页
- SSM框架实现分页和搜索分页
- SSM框架-实现分页和搜索分页
- SSM框架下的分页查询显示
- ssm框架-简单的分页查询
- SSM+mybatis数据库实现百万数据分页取出并分页插入Excel中
- JSP实现从mysql读取数据并实现分页功能
- 通过bboss persistent框架实现数据库分页查询功能
- SSM整合--ajax实现分页功能()
- ssm实现crud_mybatis分页查询(2)
- TextView跑马灯无效果及解决方法
- 启动hive hiveserver2会报警告-Mon Oct 16 10:25:12 CST 2017 WARN: Establishing SSL connection without server
- 如何把Tomcat 7.0 集成到MyEclipse里面
- 用Scratch实现的自动迷宫生成小玩具
- 微商管理系统开发源码定制
- ssm框架查询数据并实现分页功能示例
- hdu 5130 圆和多边形的面积
- BUG等级划分方法
- printk_ratelimit() 的使用
- iOS 设置相机按钮语言
- 在java中为什么main方法必须是静态的解释
- 无废话ExtJs 入门教程三[窗体:Window组件]
- android Retrofit+OKhttp实现接口调用
- s->next=head; head=s;如何理解