Vue中获取后端存放在session中的JavaBean

后端(SpringMVC)

后端把Bean存放在session作用域时,直接把Bean转为JSON Object存放(使用fastjson的jar包提供的接口进行类型转换)

	@RequestMapping("/GetLogin.do")
	public String getLogin(UserInfoForLogin user, Model model) {
		UserInfo currentUser = userDao.selectUserByNameAndPwd(user);
		if(currentUser != null) {
			model.addAttribute("currentUser", JSONObject.toJSON(currentUser));//JavaBean转换为JSON对象,供Vue中使用

 

前端获取(jsp  用到了el表达式):

Vue的data的return中:

currentUser: {}, //当前登录的用户

为了页面渲染完成时显示,放在了mounted()中

this.currentUser = ${sessionScope.currentUser};//从session中获取当前正在登录的对象

 结果:

如果把el表达式用 '' 包裹,则会变成string类型,不能用currentUser. 的方式获取用户的属性值

      var temp = '${sessionScope.currentUser}';
      console.log(typeof(temp));
      console.log('当前登录的用户的信息:\n' + temp);
      console.log(temp.userName);

结果:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值