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 ...
随机推荐
- 用rand5()生成rand(n)
问题:有函数rand5(),它能够等概率生成[0,5)之间的整数.由rand5()构造rand(n)使其能够等概率生成[0,n)之间的整数. 思路1:有rand5()先生成等概率生成0和1的rand0 ...
- Leetcode:Two Sum分析和实现
问题表示提供一个整数数组nums,以及一个目标target,要找到两个下标i与j,使得nums[i] + nums[j] = target. 最简单的思路是两次循环: for a in nums fo ...
- python子进程模块subprocess详解与应用实例 之一
subprocess--子进程管理器 一.subprocess 模块简介 subprocess最早是在2.4版本中引入的. subprocess模块用来生成子进程,并可以通过管道连接它们的输入/输出/ ...
- Linux3一些文件操作命令more,less,pr,head,tail,wc
查看文件内容命令: more和less 用cat命令可以查看文件.有时候文件太大,可以用管道符号|配合more或者less一同使用. cat <文本文件名称>|more cat < ...
- SpringBoot16 MockMvc的使用、JsonPath的使用、请求参数问题、JsonView、分页查询参数、JsonProperty
1 MockMvc的使用 利用MockMvc可以快速实现MVC测试 坑01:利用MockMvc进行测试时应用上下文路径是不包含在请求路径中的 1.1 创建一个SpringBoot项目 项目脚手架 1. ...
- jQuery div鼠标移动效果
<head runat="server"> <meta http-equiv="Content-Type" content="tex ...
- Makefile 编写规则 - 1
Makefilen内容 1. 显示规则:显示规则说明了,如何生成一个或多个目标.这是由Makefile指出要生成的文件和文件依赖的文件.2. 隐晦规则:基于Makefile的自动推导功能3. 变量的定 ...
- 性能优化之_android多线程
本文大纲为: 如何创建线程 线程间如何通讯 线程间如何安全的共享信息 一.线程的创建 Thread在run方法中执行具体事务,或者传入一个runnable对象,但是不能调用view控件的更新方法,但是 ...
- [GO]切片和底层数组的关系
package main import "fmt" func main() { a := [], , , , , , , , , } s1 := a[:] s1[] = fmt.P ...
- 编写高质量代码改善C#程序的157个建议——建议46:显式释放资源需继承接口IDisposable
建议46:显式释放资源需继承接口IDisposable C#中的每一个类型都代表一种资源,资源分为两类: 托管资源:由CLR管理分配和释放的资源,即从CLR里new出来的对象. 非托管资源:不受CLR ...