SSM整合dubbo 进行分页查询
1.先书写Mapper和sql语句
public interface ActEntityMapper {
int deleteByPrimaryKey(String actId);
int insert(ActEntity record);
int insertSelective(ActEntity record);
ActEntity selectByPrimaryKey(String actId);
int updateByPrimaryKeySelective(ActEntity record);
int updateByPrimaryKey(ActEntity record);
// 测试查询
ActEntity selectOneById(String actId) ;
/**
*
* @param size 查询数量
* @param from 偏移量
* @return
*/
List<ActEntity> selectAll(@Param("size") int size, @Param("from") int from) ;
// 查询总记录数
Integer selectListTotal();
}
ActEntityMapper.xml
<!--测试,分页查询所有信息-->
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from hx_act
limit #{from},#{size}
</select>
<!--查询表中的总记录数-->
<select id="selectListTotal" resultType="java.lang.Integer">
select
count(*)
from hx_act
</select>
<!--测试查询-->
<select id="selectOneById" resultMap="BaseResultMap" parameterType="java.lang.String">
select
act_id,
act_name,
act_desc
from hx_act
where act_id = #{actId}
</select>
2.传入的实体类、返回的实体类以及bean对象
传入实体:
@Api("查询h_act所有的信息")
public class SelectAllReq extends BaseListReq {
}
返回实体:
@Data
@Api("查询hx_act表中的所有信息")
public class SelectAllResp extends ResponseEntity {
@ApiModelProperty("返回的数据")
private List<ActBean> list ;
@ApiModelProperty("总记录数")
private int total ;
public SelectAllResp(){
super(SUCCESS);
} public SelectAllResp(String errCode) {
super(errCode);
}
}
bean对象,用于对象之间的转换:
public class ActBean extends BaseEntity {
private String actId;
private String actName;
private String actDesc;
private Integer actType;
private Integer actModel;
private Date startTime;
private Date endTime;
private String repeatType;
private Integer status;
private String shareContext;
private String extInfo;
private String joinUrl;
private Date createTime;
}
3. 书写Service接口,和具体的实现类
Service接口:
@Api(value = "杨连军测试service",produces = "application/json", description = "杨连军测试service")
public interface YangTestServiceI {
@ApiOperation("根据actId查询这条记录")
YangTestResp getActInfoById (String actId) ;
@ApiOperation("分页查询所有记录")
SelectAllResp getListInfo (SelectAllReq selectAllReq) ;
}
实现类和所需要的方法:
@ApiOperation("传入偏移量和记录数,分页查询所有记录")
@Override
public SelectAllResp getListInfo(SelectAllReq selectAllReq) {
SelectAllResp selectAllResp = new SelectAllResp() ;
List<ActBean> beanList = new ArrayList<>() ;
Integer total = actEntityMapper.selectListTotal() ;
System.out.println("总记录数:"+total);
if (null == total||total==0){
// 没有信息
selectAllResp.setErrCode(ErrorCodeConst.DATA_NOT_EXISTED);
return selectAllResp ;
}
// 调用dao,获得返回的记录
List<ActEntity> list = actEntityMapper.selectAll(selectAllReq.getSize(),selectAllReq.getFrom());
// 转换类型
beanList = converUserList(list) ;
selectAllResp.setList(beanList);
selectAllResp.setTotal(total);
return selectAllResp ;
}
/**
* @desc 不同泛型List之间的转换
* @param list
* @return
*/
public List<ActBean> converUserList(List<ActEntity> list){
List<ActBean> beanList = new ArrayList<>() ;
if (Lists.isEmpty(list)){ // 如果传入的是空,直接返回空的List<ActBean>
return beanList ;
}
for (ActEntity actEntity : list){ // 便利
ActBean actBean = new ActBean() ;
// 对象的复制
BeanUtils.copyProperties(actEntity,actBean);
beanList.add(actBean) ;
}
return beanList ;
}
4.书写控制器
// 查询所有的act信息
@RequestMapping("/getListActInfo")
@ResponseBody
public void getListActInfo (HttpServletRequest request, HttpServletResponse response,SelectAllReq selectAllReq){
System.out.println("传入参数:"+selectAllReq.getSize()); ;
SelectAllResp selectAllResp = yangTestServiceI.getListInfo(selectAllReq) ;
System.out.println("返回的状态码:"+selectAllResp.getErrCode());
resultString(selectAllResp.toJsonStr(),response,false);
}
6.需要注意的点
(1) 在消费者上书写完成接口,要进行clean,然后install,放到本地的仓库中,这样真正的消费者才能够找得到。同时,书写完成DAO的模块也要进行同样的操作。
(2) 因为真正的web端的消费者是调用的本地仓库中的包,所以在service的实现类上打断点是没有作用的;一定要做好日志的输出,好容易确定错误的位置。
SSM整合dubbo 进行分页查询的更多相关文章
- SSM整合---实现全部用户查询
SSM整合 准备 1.创建工程 2.导入必须jar包 链接: https://pan.baidu.com/s/1nvCDQJ3 密码: v5xs 3.工程结构 代码 SqlMapConfig < ...
- SpringBoot整合Mybatis关于分页查询的方法
最近公司在用到SpringBoot整合Mybatis时当web端页面数据增多时需要使用分页查询以方便来展示数据.本人对分页查询进行了一些步骤的总结,希望能够帮助到有需要的博友.如有更好的方式,也希望评 ...
- SSM整合 mybatis多条件查询与分页
多条件查询与分页: 通过页面的houseName.floorage获取值传到前端视图(HouseSearchVO)实体类中的houseName,floorage建立houseSearchVO对象. 通 ...
- SpringBoot 整合 Elasticsearch深度分页查询
es 查询共有4种查询类型 QUERY_AND_FETCH: 主节点将查询请求分发到所有的分片中,各个分片按照自己的查询规则即词频文档频率进行打分排序,然后将结果返回给主节点,主节点对所有数据进行汇总 ...
- SSM整合Dubbo案例
一.Consumer子类 MyController类 @Controller @RequestMapping("/login") public class MyController ...
- SSM整合Dubbo登陆案例
登陆案例 一.创建Service项目存放共同数据 1.1 创建实体类 private long id; private String loginName; private String userNa ...
- SSM整合之---环境搭建
SSM整合---环境搭建 l 查询所有用户的信息,保存用户信息 1.pom.xml配置项目所需的jar包 <dependencies> <dependency> <gr ...
- 商城02——dubbo框架整合_商品列表查询实现_分页
1. 课程计划 1.服务中间件dubbo 2.SSM框架整合. 3.测试使用dubbo 4.后台系统商品列表查询功能实现. 5.监控中心的搭建 2. 功能分析 2.1. 后台系统所用的技术 框 ...
- ssm实现分页查询
ssm整合实现分页查询 一.通过limit查询语句实现分页,并展示 1.mapper.xml配置 <select id="selectUsersByPage" paramet ...
随机推荐
- Jquery缩放
$(document).mousemove(function(e) { if (!!this.move) { var posix = !document.move_target ...
- webmagic使用
webmagic是Java语言用于爬虫的工具.官网地址:http://webmagic.io/,中文文档地址:http://webmagic.io/docs/zh/ 使用webmagic有3种配置需要 ...
- java基础之多线程一:概述
概述: 进程有多条执行路径, 合成为: 多线程. 进程和线程的描述: 进程: 可执行程序(文件), 例如: .exe//可以把进程理解为一辆车. 一台电脑上可以有多个进程, 这些进程之间的数据是相互隔 ...
- PHP格式化(文件)存储数据大小(SIZE)显示
有时候我们需要在网页上显示某个文件的大小,或者是其它数据的大小数字. 这个数字往往从跨度很大,如果以B为单位的话可能是个位,如果1G则长达1073741824的数字,这个时候我们就需要根据大小来格式化 ...
- Hyperledger Fabric系统架构
- vuex 数据绑定
操作文档: 安装vuex: cnpm install vuex --save 文档介绍: https://vuex.vuejs.org/guide/modules.html import Vu ...
- poj 1611 The Suspects(第一道并查集)
题意: 有N个学生,编号为0-n-1,现在0号学生感染了非典,凡是和0在一个社团的人就会感染, 并且这些人如果还参加了别的社团,他所在的社团照样全部感染,社团个数为m,求感染的人数. 输入: n代表人 ...
- JAVA读取控制台的输入【转】
前面介绍了使用IO类实现文件读写的示例,其实在很多地方还需要使用到IO类,这里再以读取控制台输入为例子来介绍IO类的使用. 控制台(Console)指无图形界面的程序,运行时显示或输入数据的位置,前面 ...
- SqlServer删除重复数据的方法
方法一 declare @max integer,@id integer open cur_rows fetch cur_rows into @id,@max begin set rowcount @ ...
- Educational Codeforces Round 62 (Rated for Div. 2)E(染色DP,构造,思维,组合数学)
#include<bits/stdc++.h>using namespace std;const long long mod=998244353;long long f[200007][2 ...