zoukankan      html  css  js  c++  java
  • SSM 中 BaseController 使用 session

    转载: http://blog.sina.com.cn/s/blog_7085382f0102v9jg.html

    public class BaseController {
    
    
    	//region HttpRequest Response Session
    	protected HttpServletRequest request;
    	protected HttpServletResponse response;
    	protected HttpSession session;
    	protected SysUser currentUser;
    
    	@ModelAttribute
    	public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){
    		this.request = request;
    		this.response = response;
    		this.session = request.getSession();
    this.currentUser=(SysUser)this.session.getAttribute("userMessage");
    	}
    
    	//endregion
    
    	//region Paged
    	protected static final String CURRENTPAGE = "1";
    	protected static final Integer PAGE_SIZE = 2;
    
    	protected Integer getTotalPage(Integer pageSize, Integer total) {
    		return total / pageSize == 0 ? total / pageSize : total / pageSize + 1;
    	}
    
    	protected PageResult getPageResult(HttpServletRequest request, Integer currentPage, Page page,
    			List list) {
    		Integer total = Integer.valueOf(String.valueOf(page.getTotal()));
        	Integer totalPage =getTotalPage(PAGE_SIZE,total);
        	PageResult pageResult = new PageResult(currentPage, PAGE_SIZE, list, total, totalPage,request.getQueryString());
    		return pageResult;
    	}
    	//endregion
        
    	
    }
    说明:@ModelAttribute的作用


    1)放置在方法的形参上:表示引用Model中的数据

    2)放置在方法上面:表示请求该类的每个Action前都会首先执行它,也可以将一些准备数据的操作放置在该方法里面。

  • 相关阅读:
    lambda表达式
    各种模块化简介及演变过程
    filter-api文档
    RegExp正则表达式规则以及常用正则表达式
    各种循环遍历对比
    条件语句对比
    莫队小结
    停更公告
    POJ2728 Desert King
    笛卡尔树Cartesian Tree
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/9779809.html
Copyright © 2011-2022 走看看