基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)

基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)

一、项目简述

功能包括:
用户管理,游戏商品管理,在线购买,上传,售卖记录,商品审核等等。
二、项目运行

环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Spring + SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等

基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)_第1张图片
基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)_第2张图片
基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)_第3张图片
基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)_第4张图片
基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)_第5张图片
基于javaweb+springboot的在线游戏商城系统(java+Springboot+MyBatis+MySQL+Maven+layui+Jsp)_第6张图片

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

                /**注册成功后存入session*/
                session.setAttribute("userid",userid);
                session.setAttribute("username",username);
                /**存入用户角色信息*/
                userRoleService.InsertUserRole(new UserRole().setUserid(userid).setRoleid(1).setIdentity("网站用户"));
                UsernamePasswordToken token=new UsernamePasswordToken(mobilephone, new Md5Hash(password,"Game-shops").toString());
                Subject subject= SecurityUtils.getSubject();
                subject.login(token);
                return new ResultVo(true,StatusCode.OK,"注册成功");
            }
            return new ResultVo(false,StatusCode.ERROR,"注册失败");
        }
        return new ResultVo(false,StatusCode.ERROR,"验证码错误");
    }
    /**登录
     * 1.判断输入账号的类型
     * 2.登录
        vCode.write(response.getOutputStream());
    }
    /**注册时发送短信验证码
     * 1.判断是否为注册类型验证码
     * 2.判断手机号格式是否正确
     * 3.判断手机号是否已经注册过
     * 4.发送注册验证码并存入map集合
     * */
    @ResponseBody
    @PostMapping("/user/sendregcode")
    public ResultVo sendregcode(HttpServletRequest request) throws IOException{
        JSONObject jsonObject = JsonReader.receivePost(request);
        final String mobilephone = jsonObject.getString("mobilephone");
        Integer type = jsonObject.getInt("type");
            return new ResultVo(true,StatusCode.SMS,"验证码发送成功");
        }else if(result == 2){
            return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
        }
        return new ResultVo(false,StatusCode.REMOTEERROR,"验证码发送失败");
    }
    /**
     * 修改绑定手机号
     * 1.获取session中userid
     * 2.修改login和userInfo中对应的手机号
    @ResponseBody
    @PostMapping("/user/avatar")
    public ResultVo userAvatar( HttpSession session) {
        String userid = (String) session.getAttribute("userid");
        UserInfo userInfo = userInfoService.queryPartInfo(userid);
        return new ResultVo(true, StatusCode.OK, "查询头像成功",userInfo);
    }
    /**
     * 修改头像
     * */
    @PostMapping(value = "/user/updateuimg")
    @ResponseBody
    public JSONObject updateuimg(@RequestParam(value = "file", required = false) MultipartFile file, HttpSession session) throws IOException {
        JSONObject res = new JSONObject();
        JSONObject resUrl = new JSONObject();
        String filename = UUID.randomUUID().toString().replaceAll("-", "");
        String ext = FilenameUtils.getExtension(file.getOriginalFilename());//获得文件扩展名
        String filenames = filename + "." + ext;//文件全名
        String pathname = "D://file/" + filenames;
        file.transferTo(new File(pathname));
        resUrl.put("src", "/pic/"+filenames);
        res.put("msg", "");
     * */
    @ResponseBody
    @PostMapping("/user/sendregcode")
    public ResultVo sendregcode(HttpServletRequest request) throws IOException{
        JSONObject jsonObject = JsonReader.receivePost(request);
        final String mobilephone = jsonObject.getString("mobilephone");
        Integer type = jsonObject.getInt("type");
        Login login = new Login();
        if(type!=0){
            return new ResultVo(false,StatusCode.ACCESSERROR,"违规操作");
        }
        if (!JustPhone.justPhone(mobilephone)) {//判断输入的手机号格式是否正确
            return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
        }
        //查询手机号是否已经注册
        login.setMobilephone(mobilephone);
        Login userIsExist = loginService.userLogin(login);
        if (!StringUtils.isEmpty(userIsExist)){//用户账号已经存在
            return new ResultVo(false, StatusCode.ERROR,"该手机号已经注册过了");
        }
        String code = GetCode.phonecode();
        Integer result = new SmsUtil().SendMsg(mobilephone, code, type);//发送验证码
            if (sessionname.equals(username)){
                UserInfo userInfo2 = userInfoService.LookUserinfo(login1.getUserid());
                if (userInfo.getUsername().equals(userInfo2.getUsername())
                        && userInfo.getEmail().equals(userInfo2.getEmail())
                        && userInfo.getSex().equals(userInfo2.getSex())
                        && userInfo.getServer().equals(userInfo2.getServer())
                ){
                    return new ResultVo(false, StatusCode.ERROR, "1.尚未修改信息");
                }
            } else {
                //如果用户名已存在
                if (!StringUtils.isEmpty(login1)) {
                    return new ResultVo(false, StatusCode.ERROR, "2.用户名已存在");
            return new ResultVo(false, StatusCode.LOGINERROR,"该账号不存在");
        }
        String rel = phonecodemap2.get(mobilephone);
        if (StringUtils.isEmpty(rel)) {//验证码到期 或者 没发送短信验证码
            return new ResultVo(false,StatusCode.ERROR,"请重新获取验证码");
        }
        if (vercode.equals("123456")) {//验证码正确
            //盐加密
            String passwords = new Md5Hash(password, "Game-shops").toString();
            login1.setPassword(passwords).setId(userIsExist.getId()).setMobilephone(null);
            userInfo.setMobilephone(mobilephone).setPassword(passwords).setUserid(userIsExist.getUserid());
            Integer integer = loginService.updateLogin(login1);
            Integer integer1 = userInfoService.UpdateUserInfo(userInfo);
            if (integer==1 && integer1==1){
                return new ResultVo(true,StatusCode.OK,"重置密码成功");
            }
            return new ResultVo(false,StatusCode.ERROR,"重置密码失败");
        }
        return new ResultVo(false,StatusCode.ERROR,"验证码错误");
            //输入的是手机号
            String mobilephone = account;
            login.setMobilephone(mobilephone);
            //将封装的login中username变为null
            login.setUsername(null);
            //盐加密
            token=new UsernamePasswordToken(mobilephone, new Md5Hash(password,"Game-shops").toString());
            System.out.println("2password :"+ token);
        }
        Subject subject= SecurityUtils.getSubject();
        try {
            subject.login(token);
            //盐加密
            String passwords = new Md5Hash(password, "Game-shops").toString();
            System.out.println("3password :"+ passwords);
            login.setPassword(passwords);
            Login login1 = loginService.userLogin(login);
            session.setAttribute("userid",login1.getUserid());
            session.setAttribute("username",login1.getUsername());
            return new ResultVo(true,StatusCode.OK,"登录成功");
        }catch (UnknownAccountException e){
        String code = GetCode.phonecode();
        Integer result = new SmsUtil().SendMsg(mobilephone, code, type);//发送验证码
        if(result == 1) {//发送成功
            phonecodemap.put(mobilephone, code);//放入map集合进行对比
/*
            final Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    phonecodemap2.remove(phoneNum);
                    timer.cancel();
                }
            }, 5 * 60 * 1000);
*/
            //执行定时任务
            ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1,
            ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1,
                    new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build());
            executorService.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    phonecodemap2.remove(mobilephone);
                    ((ScheduledThreadPoolExecutor) executorService).remove(this::run);
                }
            },5 * 60 * 1000,5 * 60 * 1000, TimeUnit.HOURS);
            return new ResultVo(true,StatusCode.SMS,"验证码发送成功");
        }else if(result == 2){
            return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
        }
        return new ResultVo(false,StatusCode.REMOTEERROR,"验证码发送失败");
    }
    /**重置密码
     * 1.判断手机号格式是否正确
     * 2.查询手机号是否存在
        }
        String rel = phonecodemap2.get(mobilephone);
        if (StringUtils.isEmpty(rel)) {//验证码到期 或者 没发送短信验证码
            return new ResultVo(false,StatusCode.ERROR,"请重新获取验证码");
        }
        if (vercode.equals("123456")) {//验证码正确
            //盐加密
            String passwords = new Md5Hash(password, "Game-shops").toString();
            login1.setPassword(passwords).setId(userIsExist.getId()).setMobilephone(null);
            userInfo.setMobilephone(mobilephone).setPassword(passwords).setUserid(userIsExist.getUserid());
    @ResponseBody
    @PostMapping("/user/resetpwd")
    public  ResultVo resetpwd(@RequestBody Login login) {
        String mobilephone=login.getMobilephone();
        String password=login.getPassword();
        String vercode=login.getVercode();
        Login login1 = new Login();
        UserInfo userInfo = new UserInfo();
        if (!JustPhone.justPhone(mobilephone)) {//判断输入的手机号格式是否正确
            return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
        String vercode = userInfo.getVercode();
        Login login = new Login().setMobilephone(mobilephone);
        //查询账号是否已经注册
        Login userIsExist = loginService.userLogin(login);
        if (!StringUtils.isEmpty(userIsExist)){//用户账号已经存在
            return new ResultVo(false, StatusCode.ERROR,"该用户已经注册过了");
        }
        login.setUsername(username).setMobilephone(null);
        Login userNameIsExist = loginService.userLogin(login);
        if (!StringUtils.isEmpty(userNameIsExist)){//用户名已经存在
            return new ResultVo(false, StatusCode.ERROR,"用户名已存在,请换一个吧");
        }
        String rel = phonecodemap1.get(mobilephone);
        if (StringUtils.isEmpty(rel)) {//验证码到期 或者 没发送短信验证码
            return new ResultVo(false,StatusCode.ERROR,"请重新获取验证码");
        }
        //if (rel.equalsIgnoreCase(vercode)) {
            if (vercode.equals("123456")) {//验证码正确
            //盐加密
    @ResponseBody
    @PostMapping("/user/updateinfo")
    public ResultVo updateInfo(@RequestBody UserInfo userInfo, HttpSession session) {
        String username = userInfo.getUsername();
        String sessionname = (String) session.getAttribute("username");
        String userid = (String) session.getAttribute("userid");
        Login login = new Login();
        //如果传入用户名不为空
        if (!StringUtils.isEmpty(username)){
            login.setUsername(username);
            Login login1 = loginService.userLogin(login);
            //如果用户名未修改
            if (sessionname.equals(username)){
        }
        if (rel.equalsIgnoreCase(vercode)) {//验证码正确
            Login login = new Login().setUserid(userid).setMobilephone(mobilephone);
            UserInfo userInfo = new UserInfo().setUserid(userid).setMobilephone(mobilephone);
            Integer integer = loginService.updateLogin(login);
            Integer integer1 = userInfoService.UpdateUserInfo(userInfo);
            if (integer == 1 && integer1 == 1) {
                return new ResultVo(true, StatusCode.OK, "更换手机号成功");
            }
            return new ResultVo(false, StatusCode.SERVERERROR, "系统错误,更换失败");
    /**
     * 展示个人信息
     */
    @RequiresPermissions("user:userinfo")
    @GetMapping("/user/lookinfo")
    public String lookinfo(HttpSession session, ModelMap modelMap) {
        String userid = (String) session.getAttribute("userid");
        UserInfo userInfo = userInfoService.LookUserinfo(userid);
        modelMap.put("userInfo",userInfo);
        return "/user/userinfo";
        String code = GetCode.phonecode();
        Integer result = new SmsUtil().SendMsg(mobilephone, code, type);//发送验证码
        if(result == 1){//发送成功
            phonecodemap1.put(mobilephone, code);//放入map集合进行对比
/*
            final Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    phonecodemap1.remove(phoneNum);
                    timer.cancel();
                }
            }, 5 * 60 * 1000);
                    phonecodemap1.remove(phoneNum);
                    timer.cancel();
                }
            }, 5 * 60 * 1000);
*/
            //执行定时任务
            ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1,
                    new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build());
            executorService.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    phonecodemap1.remove(mobilephone);
                    ((ScheduledThreadPoolExecutor) executorService).remove(this::run);
                }
            },1 * 10 * 1000,1 * 10 * 1000, TimeUnit.HOURS);
            return new ResultVo(true,StatusCode.SMS,"验证码发送成功");
        }else if(result == 2){
            return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
        }
        return new ResultVo(false,StatusCode.REMOTEERROR,"验证码发送失败");
    }
 * p>
 *
 */
@Controller
public class UserController {
    @Autowired
    private LoginService loginService;
    @Autowired
    private UserInfoService userInfoService;
    /**手机号和更换手机号验证码map集合*/
    private static Map<String, String> phonecodemap = new HashMap<>();
    /**
     * 修改密码
     * 1.前端传入旧密码(oldpwd)、新密码(newpwd)
     * 2.判断输入旧密码和系统旧密码是否相等
     * 4.修改密码
     */
    @ResponseBody
    @PutMapping("/user/updatepwd")
    public ResultVo updatepwd(HttpSession session, HttpServletRequest request) throws IOException {
        Login userIsExist = loginService.userLogin(login1);
        if (StringUtils.isEmpty(userIsExist)){//用户账号不存在
            return new ResultVo(false, StatusCode.LOGINERROR,"该账号不存在");
        }
        String rel = phonecodemap2.get(mobilephone);
        if (StringUtils.isEmpty(rel)) {//验证码到期 或者 没发送短信验证码
            return new ResultVo(false,StatusCode.ERROR,"请重新获取验证码");
        }
        if (vercode.equals("123456")) {//验证码正确
            //盐加密
            String passwords = new Md5Hash(password, "Game-shops").toString();
            login1.setPassword(passwords).setId(userIsExist.getId()).setMobilephone(null);
            userInfo.setMobilephone(mobilephone).setPassword(passwords).setUserid(userIsExist.getUserid());
            Integer integer = loginService.updateLogin(login1);
            Integer integer1 = userInfoService.UpdateUserInfo(userInfo);
            if (integer==1 && integer1==1){
                return new ResultVo(true,StatusCode.OK,"重置密码成功");
            }
            return new ResultVo(false,StatusCode.ERROR,"重置密码失败");
        }
        return new ResultVo(false,StatusCode.ERROR,"验证码错误");
    }
    /**退出登陆*/
        login.setUsername(username).setMobilephone(null);
        Login userNameIsExist = loginService.userLogin(login);
        if (!StringUtils.isEmpty(userNameIsExist)){//用户名已经存在
            return new ResultVo(false, StatusCode.ERROR,"用户名已存在,请换一个吧");
        }
        String rel = phonecodemap1.get(mobilephone);
        if (StringUtils.isEmpty(rel)) {//验证码到期 或者 没发送短信验证码
            return new ResultVo(false,StatusCode.ERROR,"请重新获取验证码");
        }
        //if (rel.equalsIgnoreCase(vercode)) {
            if (vercode.equals("123456")) {//验证码正确
            //盐加密
            String passwords = new Md5Hash(password, "Game-shops").toString();
            String userid = KeyUtil.genUniqueKey();
     * 分页展示个人已审核的商品信息(状态码:1*前端传入用户id(userid)、当前页码(nowPaging)、
     */
    @ResponseBody
    @GetMapping("/user/usercommodity/{userid}")
    public LayuiPageVo userHomeCommodity(@PathVariable("userid") String userid,int limit, int page) {
        List<Commodity> commodityList = commodityService.queryAllCommodity((page - 1) * limit, limit, userid,1);
        Integer dataNumber = commodityService.queryCommodityCount(userid,1);
        return new LayuiPageVo("", 0,dataNumber,commodityList);
    }
}
登录注册 控制器:
/**
     * 前端传入用户id(userid)
     */
    @ResponseBody
    @GetMapping("/user/userinfo/{userid}")
    public ResultVo userinfo(@PathVariable("userid") String userid) {
        UserInfo userInfo = userInfoService.LookUserinfo(userid);
        if (!StringUtils.isEmpty(userInfo)){
            return new ResultVo(true, StatusCode.OK, "查询成功",userInfo);
        }
        return new ResultVo(false, StatusCode.ERROR, "查询失败");
    }
    /**
    private static Map<String, String> phonecodemap1 = new HashMap<>();
    /**手机号和重置密码验证码map集合*/
    private static Map<String, String> phonecodemap2 = new HashMap<>();
    /**
     *图片验证码
     * */
    @RequestMapping(value = "/images", method = {RequestMethod.GET, RequestMethod.POST})
    public void images(HttpServletResponse response) throws IOException {
        response.setContentType("image/jpeg");
        //禁止图像缓存。
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        if (!JustPhone.justPhone(mobilephone)) {//判断输入的手机号格式是否正确
            return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
        }
        //查询手机号是否已经注册
        login.setMobilephone(mobilephone);
        Login userIsExist = loginService.userLogin(login);
        if (!StringUtils.isEmpty(userIsExist)){//用户账号已经存在
            return new ResultVo(false, StatusCode.ERROR,"该手机号已经注册过了");
        }
        String code = GetCode.phonecode();
        Integer result = new SmsUtil().SendMsg(mobilephone, code, type);//发送验证码
        if(result == 1){//发送成功
            phonecodemap1.put(mobilephone, code);//放入map集合进行对比
/*
            final Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    phonecodemap1.remove(phoneNum);
                    timer.cancel();
                }
            }, 5 * 60 * 1000);
*/
            //执行定时任务
                //如果用户名已存在
                if (!StringUtils.isEmpty(login1)) {
                    return new ResultVo(false, StatusCode.ERROR, "2.用户名已存在");
                }
            }
            login.setUserid(userid);
            //修改登录表中用户名
            loginService.updateLogin(login);
        }
        userInfo.setUserid(userid);
        Integer integer1 = userInfoService.UpdateUserInfo(userInfo);
        if (integer1 == 1) {
            session.setAttribute("username",username);
            return new ResultVo(true, StatusCode.OK, "修改成功");
        }
        return new ResultVo(false, StatusCode.ERROR, "修改失败");
            }
            return new ResultVo(false,StatusCode.ERROR,"注册失败");
        }
        return new ResultVo(false,StatusCode.ERROR,"验证码错误");
    }
    /**登录
     * 1.判断输入账号的类型
     * 2.登录
     * */
    @ResponseBody
    @PostMapping("/user/login")
    public ResultVo userLogin(@RequestBody Login login, HttpSession session){
        String account=login.getUsername();
        String password=login.getPassword();
        String vercode=login.getVercode();
        UsernamePasswordToken token;
        if(!ValidateCode.code.equalsIgnoreCase(vercode)){
                        && userInfo.getEmail().equals(userInfo2.getEmail())
                        && userInfo.getSex().equals(userInfo2.getSex())
                        && userInfo.getServer().equals(userInfo2.getServer())
                ){
                    return new ResultVo(false, StatusCode.ERROR, "1.尚未修改信息");
                }
            } else {
                //如果用户名已存在
                if (!StringUtils.isEmpty(login1)) {
                    return new ResultVo(false, StatusCode.ERROR, "2.用户名已存在");
                }
            }
            login.setUserid(userid);
            //修改登录表中用户名
            loginService.updateLogin(login);
        }
        String ext = FilenameUtils.getExtension(file.getOriginalFilename());//获得文件扩展名
        String filenames = filename + "." + ext;//文件全名
        String pathname = "D://file/" + filenames;
        file.transferTo(new File(pathname));
        resUrl.put("src", "/pic/"+filenames);
        res.put("msg", "");
        res.put("code", 0);
        res.put("data", resUrl);
        String uimgUrl = "/pic/" + filenames;
        String userid=(String) session.getAttribute("userid");
        UserInfo userInfo = new UserInfo().setUserid(userid).setUimage(uimgUrl);
        userInfoService.UpdateUserInfo(userInfo);

你可能感兴趣的:(java,mysql)