NoSession问题

第一种原因:

 no Session 错误
 dao层中get方法换成了load方法,或者其他原因引起.
 原因分析: 真正用到代理对象的时候,代理对象没有值,并且session的生命周期已经走完了.
 解决方案:1,load()换成get(),或者立即查询,比如打印一下.
      2,延长session的存活时间,---- OpenSessionInViewFilter
web.xml中配置:
  <!-- 延长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
  初始化快递员对象中 定区集合
  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;
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值