cookie存值和page分页
一.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 dpostfrom claim_voucher cvleft join employee ce on ce.sn=cv.create_snleft join employee d on d.sn = cv.next_deal_snwhere 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实现层
@Overridepublic 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);}}}%>
转载于:https://www.cnblogs.com/szjbk/p/10941089.html
cookie存值和page分页相关推荐
- page分页问题,根据页码获取对应页面的数据,接口调用
添加一个log.js文件,进行接口调用. import axios from '@/libs/api.request'const MODULE_URL = '/log';export const ac ...
- cookies的存值问题
2019独角兽企业重金招聘Python工程师标准>>> cookies存值问题,项目中遇到问题初始化时由于cookies中存在冒号导致存到cookies中时取出来被转码了,冒号的转码 ...
- Servlet/JSP(2)-数据共享(Cookie Session等),分页
文章目录 数据共享 1. cookie 2. sendRedrect() 3. 隐藏表单 4. Session 程序 Servlet-JDBC:与数据库的连接 分页技术 分页算法 翻页 效率 Cook ...
- 微信小程序动画渐入以及动态存值setdata问题
微信小程序动画渐入以及动态存值setdata问题 想要在微信小程序中制作多个元素逐一渐入的效果,效果类似下图: 首先参考微信开发文档API动画部分的内容 开发文档API–动画Animation 创建动 ...
- php如何获取cookie,怎么获取cookie的值
获取cookie值的方法:首先通过[document.cookie]获取所有的cookie值:然后由于得到的是所有值在一起的字符串可以用split函数将字符串分割开变成数组:最后判断数组中有没有包含c ...
- iview page分页组件的集成
iview page分页组件的集成 今天给大家分享一下iview page分页组件与iview table表格的集成,主要是针对前端集成,整个前端采用vue渲染,首先我们查看一 ...
- page分页php,Page分页函数
提供一款实例的分类函数,有需要的朋友可以参考一下.<?php教程 // page分页函数 $page = $_get["page"]; function page($rows ...
- Map存值问题的研究
2019独角兽企业重金招聘Python工程师标准>>> java中在map中存取值操作 在java中map是使用键值对的形式存在的这与数组非常的相似.Map是一个接口它当中包括:Ha ...
- java修改cookie的值_Java 对 Cookie增删改查的实现示例
Cookie属性 name:cookie的名称 value:cookie的值 maxAge:cookie的失效时间,默认为-1 值 说明 负数 浏览器关闭后立即失效 0 马上清除cookie 正数 设 ...
最新文章
- 第一个晶体管是如何工作的?
- springMVC--(讲解5)文件上传与传参测试
- MATLAB找不到遗传算法工具箱,用不了gatool命令的解决方案
- Spring系列之AOP实现的两种方式
- 忘记SAP系统Client 000的所有账号密码
- codeforces E. Picking Strings 构造
- leetcode1432. 改变一个整数能得到的最大差值(贪心)
- python 编辑数学公式_Jupyter快速编辑高大上数学公式 泰勒展开式
- WPF 使用皮肤影响按钮自定义
- Linux编译安装PHP7.4.24及启动
- 计算机关机又自动重启,电脑关机后自动重启是什么原因?Win10关机变重启原因及解决方法...
- python股票回测_从啥都不会试着用python做均线回测--1
- HDU -2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(DP,贪心)
- redis数据库指令
- 文墨绘学【书法双师】
- root下备份mysql_如何用指令行备份mysql下所有数据库
- 毕业论文 | 基于安卓手机蓝牙控制的智能小车设计(源代码)
- libvirt 详解(2)
- FFmpeg动效实践与探索(文字方框的同步展开及收缩)
- 2023版Python数据分析,学习路径拆解及资源推荐(附详细思维导图)