首页>代码>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);*/
    }



}
最近下载更多
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日
圈布拉克拉夸  LV1 2021年11月2日
最近浏览更多
GJQ123  LV4 2023年12月29日
chenlie  LV2 2023年11月13日
xiao小果  LV12 2023年9月11日
飞呀飞呀飞不放  LV7 2023年8月9日
shaoqi 2023年7月26日
暂无贡献等级
abrnya  LV1 2023年5月30日
lyd1233456  LV1 2023年2月21日
消防超高层防风衣 2022年12月27日
暂无贡献等级
xxg634460601  LV3 2022年12月19日
小赤0120  LV4 2022年12月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友