一、项目简述
功能包括:
用户管理,游戏商品管理,在线购买,上传,售卖记录,商品审核等等。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
@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);
}
}
登录注册 控制器:
/**
* <p>
* 登录注册 控制器
* </p>
*
*/
@Controller
public class LoginController {
@Autowired
private LoginService loginService;
@Autowired
private UserInfoService userInfoService;
@Autowired
private UserRoleService userRoleService;
/**手机号和注册验证码map集合*/
private static Map<String, String> phonecodemap1 = new HashMap<>();
/**手机号和重置密码验证码map集合*/
private static Map<String, String> phonecodemap2 = new HashMap<>();
/**
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(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();
}
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);
return res;
}
/**
* 展示个人信息
*/
@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";
}
/**
* 跳转到完善个人信息
*/
*/
//执行定时任务
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,"验证码发送失败");
}
/**注册
* 1.前端传入用户名(username)、密码(password)、邮箱(email)、手机号(mobilephone)、验证码(vercode)
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);
return res;
}
/**
* 展示个人信息
*/
@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 username = (String)session.getAttribute("username");
if(StringUtils.isEmpty(userid) && StringUtils.isEmpty(username)){
return "redirect:/";
}
request.getSession().removeAttribute("userid");
request.getSession().removeAttribute("username");
return "redirect:/";
}
}
个人中心 控制器:
/**
* <p>
* 个人中心 控制器
* </p>
*
*/
@Controller
public class UserController {
@Autowired
private LoginService loginService;
@Autowired
private UserInfoService userInfoService;
@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");
response.setDateHeader("Expires", 0);
ValidateCode vCode = new ValidateCode(820, 200, 5, 80);
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(false,StatusCode.ERROR,"重置密码失败");
}
return new ResultVo(false,StatusCode.ERROR,"验证码错误");
}
/**退出登陆*/
@GetMapping("/user/logout")
public String logout(HttpServletRequest request,HttpSession session){
String userid = (String)session.getAttribute("userid");
String username = (String)session.getAttribute("username");
if(StringUtils.isEmpty(userid) && StringUtils.isEmpty(username)){
return "redirect:/";
}
request.getSession().removeAttribute("userid");
request.getSession().removeAttribute("username");
return "redirect:/";
}
}
个人中心 控制器:
String vercode=login.getVercode();
Login login1 = new Login();
UserInfo userInfo = new UserInfo();
if (!JustPhone.justPhone(mobilephone)) {//判断输入的手机号格式是否正确
return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
}
//查询手机号是否存在
login1.setMobilephone(mobilephone);
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);
private LoginService loginService;
@Autowired
private UserInfoService userInfoService;
@Autowired
private UserRoleService userRoleService;
/**手机号和注册验证码map集合*/
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 {