发表于: 2017-11-03 21:46:32

0 880


今天做的事:

今天又写了两个接口,本地自测了一下,没什么问题,服务器代码传不上去,出了点问题,要改svn代码还要和阿飞商量,然后他也还没回我,再说吧。


一个是更改用户状态接口,冻结正常什么的。

if(status == 1){
status = 2;
}else {
status = 1;
}

可能就这值得写?感觉没什么值得写的。。。


剩下那个接口就比较了不起了,动态查询接口:

public static Map<String, Object> getDynamicUserList(String alias, Integer sex, Integer grade, String mobile, String mail,
                                                    Integer status, Integer beansBegin, Integer beansEnd, String location) {

Map<String, Object> params = new HashMap<>();
   
   if (DataUtils.isNotNullOrEmpty(alias)) {
params.put(" user.alias & = ", "'" + alias + "'");
   }
if (DataUtils.isNotNullOrEmpty(sex)) {
params.put(" user.sex & =", " '" + sex + "'");
   }
if (DataUtils.isNotNullOrEmpty(grade)) {
params.put(" user.grade & = ", "'" + grade + "'");
   }
if (DataUtils.isNotNullOrEmpty(mobile)) {
params.put(" user.mobile & = ", "'" + mobile + "'");
   }
if (DataUtils.isNotNullOrEmpty(mail)) {
params.put(" user.mail & =", " '" + mail + "'");
   }
if (DataUtils.isNotNullOrEmpty(status)) {
params.put(" user.status & = ", "'" + status + "'");
   }
if (DataUtils.isNotNullOrEmpty(beansBegin)) {
params.put(" user.beans & > ", "'" + beansBegin + "'");
   }
if (DataUtils.isNotNullOrEmpty(beansEnd)) {
params.put(" user.beans & < ", " '" + beansEnd + "'");
   }
if (DataUtils.isNotNullOrEmpty(location)) {
params.put(" user.location & = ", "'" + location + "'");
   }

params.put("@order", "create_at desc");
   params.put("@query", "id");

   
   params.put("@table", "user");

   String s = SQLUtil.convert2Sql(params, 0, Integer.MAX_VALUE);
   System.out.println(s);

   return params;

}


工具类,首先判空,非空就往sql中加参数,最后拼接出来;


之后是controller中的

if(page == null || page <= 0){
page = 1;
}
if(size == null || size <= 0){
size = 10;
}
int start = (page - 1) * size;
if(start < 0){
start = 0;
}


页码,页长,起始值;


//用户总数
List<Long> userIds = userService.getIdsByDynamicCondition(User.class, params,0,Integer.MAX_VALUE);
        int count = userIds.size();
        log.info("count : " + count);
        //分页返回用户列表
List<Long> limitUserIds = userService.getIdsByDynamicCondition(User.class, params,start,size);
        List<User> userList = userService.getObjectsByIds(limitUserIds);
        log.info("userList : " + userList);

第二个list返回分页后的列表;


 //页数多少
int pages = count/size;
if(count%size != 0){
pages += 1;
}
log.info("pages : " + pages);
//是否有下一页
boolean nextPage = false;
if(page < pages){
nextPage = true;
}
log.info("nextPage : " + nextPage);


计算页数以及下一页是否存在。


写的时候还遇到一个报错:

Optional int parameter 'page' is present but cannot be translated into a null value due to being dec


类似上面那个,原因是,我的入参设置为int类型,但是int类型不可以设置为null,所以必须使用Integer包装类。


一会更新一下接口文档。


明天计划:继续写接口


问题:暂无


收获:公司框架现在用的渐渐得心应手了,不过比较难得部分还在后面,比如文件上传和微信相关的内容什么的。




返回列表 返回列表
评论

    分享到