Ai
1 Star 0 Fork 0

杰编程/java_idea

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
UserController.java 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
杰编程 提交于 2023-11-08 17:20 +08:00 . 登录
package com.example.learnspring.controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* Created with IntelliJ IDEA.
* Description:
*
* @author: zxj
* @date: 2023-11-07
* @time: 21:35:49
*/
@RequestMapping("/user")
@RestController
public class UserController {
@RequestMapping("login")
public Boolean login(String userName, String password, HttpServletRequest request) {
if (!StringUtils.hasLength(userName)||!StringUtils.hasLength(password)) {
return false;
}
HttpSession session = request.getSession(true);
session.setAttribute("userName",userName);
return true;
}
@RequestMapping("/getLoginUsername")
public String getLoginUsername(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session == null) {
return "";
}
return (String) session.getAttribute("userName");
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/zxj2022/java_idea.git
git@gitee.com:zxj2022/java_idea.git
zxj2022
java_idea
java_idea
master

搜索帮助