首页>代码>spring boot+spring mvc+springdata jpa实现简单的用户登录注册系统>/ycuser/src/main/java/com/example/ycuser/controller/UserController.java
package com.example.ycuser.controller; import com.example.ycuser.entity.User; import com.example.ycuser.service.UserService; import com.example.ycuser.service.UserServiceImp; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @RestController public class UserController { @Resource private UserServiceImp usi; //以下是登录 @RequestMapping(value = "/userLogin/submit",method = RequestMethod.POST) public boolean userLogin(HttpServletRequest request){ String username = request.getParameter("username"); String password = request.getParameter("password"); System.out.println(username); if (usi.findUserByUsernameAndPassowrd(username,password)==null){ return false; } return true; } //以下是注册 @RequestMapping(value = "/userRegister/submit",method = RequestMethod.POST) public boolean userRegister(HttpServletRequest request){ String username = request.getParameter("username"); String password = request.getParameter("password"); int lengthusername = username.length(); int lengthpassword = password.length(); if ((lengthpassword >= 8 && lengthpassword <= 15) && (lengthusername >= 8 && lengthusername <= 15)) { if (usi.findUserByUsername(username)==null){ User u =new User(username,password); return usi.addUser(u); }else{return false;} /*User u =new User(username,password); return usi.addUser(u);*/ } else { /*return "账号或密码长度应为10--20,请正确输入";*/ return false; } /* User u =new User(username,password); return usi.addUser(u);*/ } }

刘代香 LV1
2024年6月15日
GJQ123 LV4
2023年12月29日
abrnya LV1
2023年5月30日
ajdgqd LV3
2022年11月1日
cgfeng12345 LV10
2022年10月14日
liuxiao2 LV16
2022年9月23日
super12 LV1
2022年7月28日
SCL_5757 LV1
2022年5月14日
1037491525 LV1
2022年4月8日
ksk23333 LV5
2022年3月19日

xiaoaitx LV8
2024年11月18日
bluerstar LV1
2024年10月23日
xuxuer
2024年9月26日
暂无贡献等级
ma406805131 LV19
2024年6月28日
TY0165 LV20
2024年6月24日
szqqqaaqqa LV1
2024年6月21日
qiwwwww LV2
2024年6月20日
计科一班 LV7
2024年6月18日
刘代香 LV1
2024年6月15日
不正经的90后程序猿 LV1
2024年6月1日