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 ...
随机推荐
- 【bzoj1479】[NOI2006]最大获利
1497: [NOI2006]最大获利 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 4335 Solved: 2123[Submit][Status] ...
- 使用百度翻译的API接口
http://api.fanyi.baidu.com/api/trans/product/desktop 这是申请的接口地址,会得到一个APPID和一个钥密 然后下载PHP的对应的代码 有一个PHP文 ...
- 场景中,并没有灯源的存在,但是cube却会有灯光照射的反应,这就是Light Probe Group的作用。
http://blog.csdn.net/qq617119142/article/details/41674755
- java中的监听事件
java监听器实现的类 1.ServletContextListener:对servlet上下文的创建和销毁监听 2.ServletContextAttributeListener:监听servlet ...
- jQuery--后台主机列表编辑
先看效果: 要求: 全选,反选和取消 编辑模式下的全选,反选和取消 编辑模式下单选进入编辑状态,取消退出编辑状态 表格元素有可编辑,不可编辑,下拉选择 按住ctrl选择下拉框,下面的同列选项都随之改变 ...
- jquery中children()
- 符合mvc思维的分页思想
.Model Student.cs namespace WebApplication14.Models { public class Student { public int Id { get; se ...
- 登录到 SQL Server 实例
登录到 SQL Server 实例(命令提示符) 登录到 SQL Server 的默认实例 从命令提示符输入以下命令,使用 Windows 身份验证进行连接: sqlcmd [ /E ] ...
- Spring MVC:Model、View、ModelAndView
个人理解:View为服务器上的某个文件容器,可以为JSP,FTL等动态页面文件,甚至是媒体文件等等,单单是一个文件.Model的作用是存储动态页面属性,动态页面文件即View可以在Model中获取动态 ...
- C# 的 Task、Thread、ThreadPool 之间有什么异同?
Thread就是Thread,需要自己调度,适合长跑型的操作. ThreadPool是Thread基础上的一个线程池,目的是减少频繁创建线程的开销.线程很贵,要开新的stack,要增加CPU上下文切换 ...