你的位置:首页 > 软件开发 > Java > NoSession问题

NoSession问题

发布时间:2017-08-17 18:00:13
第一种原因: no Session 错误 dao层中get方法换成了load方法,或者其他原因引起. 原因分析: 真正用到代理对象的时候,代理对象没有值,并且session的生命周期已经走完了. 解决方案:1,load()换成get(),或者立即查询,比如打印一 ...

NoSession问题

第一种原因:

 no Session 错误
 dao层中get方法换成了load方法,或者其他原因引起.
 原因分析: 真正用到代理对象的时候,代理对象没有值,并且session的生命周期已经走完了.
 解决方案:1,load()换成get(),或者立即查询,比如打印一下.
      2,延长session的存活时间,---- OpenSessionInViewFilter
web.  <!-- 延长session存活时间 -->
  <filter>
      <filter-name>OpenSession</filter-name>
      <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
      <filter-name>OpenSession</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
 NoSession问题

 

第二种原因:

NoSession
  初始化快递员对象中 定区集合
  web层转Courier对象为json串时候,对象中有fixedareas集合属性,jpa加载策略延迟加载。
  在action中转fixedareas集合为json串,通过代理对象查询数据库,action中session已经关闭。

解决方案:不转fixedareas集合。

 

 /**  * @Description: 快递员分页  * @return  * @throws Exception  *   */ @Action("courierAction_pageQuery") public String pageQuery() throws Exception {  Pageable pageable = new PageRequest(page-1, rows);  Page<Courier> page = courierService.findAll(pageable);    Map<String, Object> map = new HashMap<>();  map.put("total", page.getTotalElements());  map.put("rows", page.getContent());    //将fixedares集合属性排除掉,不转json  JsonConfig jsonConfig = new JsonConfig();   jsonConfig.setExcludes(new String[]{"fixedAreas"});    String json = JSONObject.fromObject(map, jsonConfig).toString();    ServletActionContext.getResponse().setContentType("text/json;charset=utf-8");  ServletActionContext.getResponse().getWriter().write(json);  return NONE; }

 

原标题:NoSession问题

关键词:session

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录