今天写到积分签到功能,从开始进行需求分析的时候就觉得积分签到最麻烦,平时在使用签到功能觉得点一下签到按键就好了,今天写起来弯弯绕绕的觉得很是麻烦,先把刚写完的一个功能分享出来吧。
主要采用MVC框架。
微信商城签到天数sql语句:
sql = "SELECT COUNT(DISTINCT(poi_date)) AS sumday FROM points WHERE poi_del = ? AND u_id =?";
Service:
public SumModel sumSignDay(UserModel user){ sql = "SELECT COUNT(DISTINCT(poi_date)) AS sumday FROM points WHERE poi_del = ? AND u_id =?"; data = db.query(sql, 0,user.getU_id()); return mapToSumSignDayModel(data).get(0); }
//泛型转换sumSignDay public List mapToSumSignDayModel(List> data){ List list = new ArrayList<>(); SumModel sumModel = null; for (Map map : data) { sumModel = new SumModel( Integer.parseInt(map.getOrDefault("sumday", "").toString())); list.add(sumModel); } return list; }
Servlet:
request.setAttribute("userSumSignInfo", pointService.sumSignDay(userModel));
JSP:
<% SumModel sumSD = (SumModel)request.getAttribute("userSumSignInfo"); %>
已签到天数:<%=sumSD.getSum() %>