一.page分页
1.dao层
List<ClaimVoucher> findAll(@Param("map")HashMap<String,Object> map,@Param("csn")String csn );;//分页查找
2.dao中配置文件sql语句
<resultMap id="claimVoucher" type="ClaimVoucher">
<id property="id" column="id" javaType="int"/>
<result property="cause" column="cause" javaType="String"/>
<result property="create_sn" column="create_sn" javaType="String"/>
<result property="create_time" column="create_time" javaType="java.util.Date"/>
<result property="next_deal_sn" column="next_deal_sn" javaType="String"/>
<result property="total_amount" column="total_amount" javaType="Double"/>
<result property="status" column="status" javaType="String"/>
<association property="creater" column="create_sn" javaType="Employee">
<result property="name" column="cname" javaType="String"/>
<result property="post" column="cpost" javaType="String"/>
</association>
<association property="dealer" column="next_deal_sn" javaType="Employee">
<result property="name" column="dname" javaType="String"/>
<result property="post" column="dpost" javaType="String"/>
</association>
</resultMap>
<select id="findAll" resultMap="claimVoucher" > select cv.*,ce.name cname,ce.post cpost,d.name dname,d.post dpost from claim_voucher cv left join employee ce on ce.sn=cv.create_sn left join employee d on d.sn = cv.next_deal_sn where cv.create_sn=#{csn} order by cv.create_time desc <if test="map.start!=null and map.size!=null"> limit #{map.start},#{map.size} </if> </select>
3.service层
//分页查询 Pages<ClaimVoucher> findAll(int currPage,String csn);
4.service实现层
@Override public Pages<ClaimVoucher> findAll(int currPage, String csn) { HashMap<String,Object> map = new HashMap<String,Object>(); Pages<ClaimVoucher> pages = new Pages<ClaimVoucher>(); //封装当前页数 pages.setCurrPage(currPage); //每页显示的数据 int pageSize=5; pages.setPageSize(pageSize); //封装总记录数 int totalCount = claimVoucherDao.totalCount(csn); pages.setTotalCount(totalCount); //封装总页数 double tc = totalCount; Double num =Math.ceil(tc/pageSize);//向上取整 pages.setTotalPage(num.intValue()); map.put("start",(currPage-1)*pageSize); map.put("size", pages.getPageSize()); //封装每页显示的数据 List<ClaimVoucher> lists = claimVoucherDao.findAll(map,csn); pages.setLists(lists); return pages; }
5.controller控制层
@RequestMapping("/self") public String self(@RequestParam(value = "currentPage",defaultValue = "1",required = false) int currentPage, Map<String,Object> map,HttpSession session){ Employee employee = (Employee)session.getAttribute("employee"); map.put("pageinfo",claimVoucherBiz.findAll(currentPage,employee.getSn())); return "claim_voucher_self"; }
二.cookie存值
1.后端
@RequestMapping("/login") public String login(HttpServletResponse response,HttpSession session, @RequestParam String sn, @RequestParam String password, HttpServletRequest request){ Employee employee = globalBiz.login(sn,password); if(employee == null){ return "redirect:to_login"; } session.setAttribute("employee",employee); String remember = request.getParameter("remember"); Cookie[] cookies = request.getCookies(); if("on".equals(remember)){ //创建cookie对象 Cookie cookie = new Cookie("usemsg",sn+"-"+password); //设置保存时间为一分钟 cookie.setMaxAge(60*60*24); //将cookie进行存储 response.addCookie(cookie); System.out.println(cookie.getValue()); }else{ Cookie cookie = new Cookie("usemsg",null); //设置过期时间 10分钟 cookie.setMaxAge(0); //储存 cookie.setPath("/"); response.addCookie(cookie); } return "redirect:self"; }
2.前端
<% String sn = null; String password = null; Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals("usemsg")) { if(cookies[i].getValue()!=null){ sn = cookies[i].getValue().split("-")[0]; password = cookies[i].getValue().split("-")[1]; request.setAttribute("gh", sn); request.setAttribute("mm", password); } } } %>