统计用户绑定手机情况
- 在vo文件夹中创建BindPhoneStatistics.java-----用来传递共有的值
package com.xx.vo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor public class BindPhoneStatistics { private long value; private String name; }
2.在UserDao.java中添加方法
Long bindPhoneCount();//手机绑定的数量 Long unBindPhoneCount();//手机未绑定的数量
3.在UserDaoMapper.xml中添加查询方法
<!--查询绑定手机的数量--> <select id="bindPhoneCount" resultType="java.lang.Long"> select count(1) from `user` where phone is NOT Null </select> <!--查询未绑定手机的数量--> <select id="unBindPhoneCount" resultType="java.lang.Long"> select count(1) from `user` where phone is Null </select>
4.在service层的实现
UserService
List<BindPhoneStatistics> getPhoneStatistics(); //在UserService文件中层, 编写统计手机号的绑定情况的方法
UserServiceImpl
/* 统计手机用户的绑定情况 */ @Override public List<BindPhoneStatistics> getPhoneStatistics() { Long bindPhoneCount= userDao.bindPhoneCount(); BindPhoneStatistics bindPhone=new BindPhoneStatistics(bindPhoneCount,"已绑定") ; Long unBindPhoneCount=userDao.unBindPhoneCount(); BindPhoneStatistics unBindPhone= new BindPhoneStatistics(unBindPhoneCount,"未绑定"); return Arrays.asList(bindPhone,unBindPhone); }
5.在UserController.java中的实现
/* 统计手机绑定情况 */ @RequestMapping("getPhone") public List<BindPhoneStatistics> getPhonStatistics(){ return userService.getPhoneStatistics(); }
6.开发声明
1)lombok是一款在java开发中简洁化代码十分有用的插件工具,以下均是该中的注解
2)@Data:使用这个注解,就不用再去手写Getter,Setter, equals,canEqual,hasCode,toString等方法了,注解后在编译时会自动加进去;
3)@AllArgsConstructor:使用后添加一个构造函数,该构造函数含有所有已声明字段属性参数;
4)@NoArgsConstructor:使用后创建一个无参构造函数;
本文来自博客园,作者:尔尔er,转载请注明原文链接:https://www.cnblogs.com/erer123/p/17310337.html