【日京的学生信息管理系统】springboot+vue用户登录之后显示用户名
·
项目源码github地址一直在更新…https://github.com/rijing29/RjStuManagement
整个功能实现的流程图
1.LoginController.java
package com.whj.stumanagement.rj_stumanagement_back.controller;
import com.whj.stumanagement.rj_stumanagement_back.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/stu")
public class loginController {
@Autowired
private StuService stuService;
@RequestMapping(value = "/login",produces = "application/json;charset=utf-8")
public List login(HttpServletRequest request, @RequestParam("sname") String sname, @RequestParam("spwd") String spwd){
int code=404;
boolean res = stuService.login(sname, spwd);
if(res) {
code = 200;
System.out.println("登录成功");
// 定义session对象并把数据存入session
HttpSession session = request.getSession();
session.setAttribute("sname",sname);
session.setAttribute("spwd",spwd);
}else
System.out.println("登陆失败,用户名或密码错误");
// 返回状态码和登录名
ArrayList<Object> result = new ArrayList<>();
result.add(0,code);
result.add(1,sname);
return result;
}
}
2.login.vue
// 登录
login(){
var url="/login"
var params={
'sname':this.sname,
'spwd':this.spwd
}
this.$http.get(url,{params}).then(res=>{
this.result=res.data
if(res.data[0]==200){
this.$message.success('登陆成功')
// 传用户名到home.vue
this.$router.push({
path:'/home',
query:{
sname:res.data[1]
}
})
}else{
this.$message.error('登陆失败,用户名或密码错误')
}
})
},
3.home.vue
// 获取用户名
getSname(){
var sname=this.$route.query.sname
this.sname=sname
console.log("传过来的sname")
console.log(this.sname)
},
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)