基于javaweb+mysql的springboot在线游戏商城系统(java+springboot+mybatis+mysql+maven+layui+thymeleaf+html)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线游戏商城系统(java+springboot+mybatis+mysql+maven+layui+thymeleaf+html)
一、项目简述功能包括: 用户管理,游戏商品管理,在线购买,上传,售卖记录,商品审核等等。
二、项目运行环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
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);
*/
//执行定时任务
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)
* 2.查询账号是否已经注册
* 3.查询用户名是否已存在
* 4.判断验证码是否有效或正确
* 5.注册
* */
@ResponseBody
@PostMapping("/user/register")
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
/**
*/
@ControllerAdvice
public class GloableExceptionAop {
/**
* shiro异常
* */
@ExceptionHandler(value = UnauthorizedException.class)//处理访问方法时权限不足问题
public String defaultErrorHandler() {
return "redirect:/noAuth";
}
/**
* runtime异常
* */
@ExceptionHandler(RuntimeException.class)
@ResponseBody
public String runtimeException(){
return "出现runtime异常了,这里在捕获全局异常,相当于手写AOP捕获异常。";
}
}
* 1.前端传入商品id(commid)、商品名(commname)、商品描述(commdesc)、商品用户id(cmuserid)
* 商品用户名(username)、商品所在游戏(server)
* 2.session中获取收藏用户id(couserid)
* 3.进行收藏操作
* (2). 取消收藏
* 1.前端传入商品id(commid)
* 2.判断是否本人取消收藏
* 3.进行取消收藏操作
*/
@ResponseBody
@PostMapping("/collect/operate")
public ResultVo insertcollect(@RequestBody Collect collect, HttpSession session){
String couserid = (String) session.getAttribute("userid");
Integer colloperate = collect.getColloperate();
collect.setCouserid(couserid);
if (StringUtils.isEmpty(couserid)){
return new ResultVo(false, StatusCode.ACCESSERROR,"请先登录");
}
if (colloperate == 1){
Collect collect1 = collectService.queryCollectStatus(collect);
if(!StringUtils.isEmpty(collect1)){
/**更改原来的收藏信息和状态*/
collect1.setCommname(collect.getCommname()).setCommdesc(collect.getCommdesc()).setServer(collect.getServer())
.setSoldtime(GetDate.strToDate());
Integer i = collectService.updateCollect(collect);
if (i == 1){
return new ResultVo(true, StatusCode.OK,"收藏成功");
}
return new ResultVo(false,StatusCode.ERROR,"收藏失败");
}else{
collect.setId(KeyUtil.genUniqueKey());
Integer i = collectService.insertCollect(collect);
if (i == 1){
return new ResultVo(true, StatusCode.OK,"收藏成功");
}
return new ResultVo(false,StatusCode.ERROR,"收藏失败");
}
}else {
Collect collect1 = collectService.queryCollectStatus(collect);
/**判断是否为本人操作*/
if (collect1.getCouserid().equals(couserid)){
Integer i = collectService.updateCollect(collect);
if (i == 1){
return new ResultVo(true, StatusCode.OK,"取消成功");
}
return new ResultVo(false,StatusCode.ERROR,"取消失败");
}
return new ResultVo(false,StatusCode.ACCESSERROR,"禁止操作");
}
//
//
///**
// */
全局日志管理
//@Aspect
//@Component
//@Slf4j
//public class WebLogAspect {
//
// @Pointcut("execution(public * com.controller..*.*(..))")
// public void webLog() {
// }
//
// @Before("webLog()")
// public void doBefore(JoinPoint joinPoint) throws Throwable {
// // 接收到请求,记录请求内容
// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpServletRequest request = attributes.getRequest();
// // 记录下请求内容
// log.info("URL : " + request.getRequestURL().toString());
// log.info("HTTP_METHOD : " + request.getMethod());
// log.info("IP : " + request.getRemoteAddr());
// Enumeration<String> enu = request.getParameterNames();
// while (enu.hasMoreElements()) {
// String name = (String) enu.nextElement();
// log.info("name:{},value:{}", name, request.getParameter(name));
// }
// }
//
// @AfterReturning(returning = "ret", pointcut = "webLog()")
// public void doAfterReturning(Object ret) throws Throwable {
// // 处理完请求,返回内容
// log.info("RESPONSE : " + ret);
// }
//}
/**
* 删除售出记录
* 1.前端传入需删除记录的id(id)
* 2.判断是否是本人
* */
@ResponseBody
@PutMapping("/soldrecord/delect/{id}")
public ResultVo delectSold (@PathVariable("id") String id) {
Integer i = soldrecordService.deleteSold(id);
if (i == 1){
return new ResultVo(true, StatusCode.OK,"删除记录成功");
}
return new ResultVo(false, StatusCode.ERROR,"删除记录失败");
}
/**
* 分页查看用户所有售出记录
* 1.前端传入页码、分页数量
* 2.查询分页数据
*/
@ResponseBody
@GetMapping("/soldrecord/lookuser")
public LayuiPageVo LookUserSold(int limit, int page, HttpSession session) {
String userid = (String) session.getAttribute("userid");
//如果未登录,给一个假id
if(StringUtils.isEmpty(userid)){
userid = "123456";
}
List<Soldrecord> soldrecordList = soldrecordService.queryAllSoldrecord((page - 1) * limit, limit, userid);
Integer dataNumber = soldrecordService.querySoldCount(userid);
return new LayuiPageVo("",0,dataNumber,soldrecordList);
}
/**
* 分页查看全部的售出记录
* 1.前端传入页码、分页数量
* 2.查询分页数据
*/
@ResponseBody
@GetMapping("/soldrecord/queryall")
public LayuiPageVo queryAllSold(int limit, int page) {
List<Soldrecord> soldrecordList = soldrecordService.queryAllSoldrecord((page - 1) * limit, limit, null);
Integer dataNumber = soldrecordService.querySoldCount(null);
return new LayuiPageVo("",0,dataNumber,soldrecordList);
}
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
/**
*/
@ControllerAdvice
public class GloableExceptionAop {
/**
* shiro异常
* */
@ExceptionHandler(value = UnauthorizedException.class)//处理访问方法时权限不足问题
public String defaultErrorHandler() {
return "redirect:/noAuth";
}
/**
* runtime异常
* */
@ExceptionHandler(RuntimeException.class)
@ResponseBody
public String runtimeException(){
return "出现runtime异常了,这里在捕获全局异常,相当于手写AOP捕获异常。";
}
}
/**解析ajax的请求*/
public class JsonReader {
public static JSONObject receivePost(HttpServletRequest request) throws IOException {
// 读取请求内容
modelMap.put("collectstatus",2);
}
}
return "/common/product-detail";
}else{
return "/error/404";
}
}
/**
* 搜索商品分页数据
* 前端传入搜索的商品名(commname)
* */
@GetMapping("/product/search/number/{commname}")
@ResponseBody
public PageVo searchCommodityNumber(@PathVariable("commname") String commname){
Integer dataNumber = commodityService.queryCommodityByNameCount(commname);
return new PageVo(StatusCode.OK,"查询成功",dataNumber);
}
/**
* 搜索商品
* 前端传入当前页数(nowPaging)、搜索的商品名(commname)
* */
@GetMapping("/product/search/{nowPaging}/{commname}")
@ResponseBody
public ResultVo searchCommodity(@PathVariable("nowPaging") Integer page, @PathVariable("commname") String commname){
List<Commodity> commodityList = commodityService.queryCommodityByName((page - 1) * 20, 20, commname);
if(!StringUtils.isEmpty(commodityList)){//如果有对应商品
for (Commodity commodity : commodityList) {
/**查询商品对应的其它图片*/
List<String> imagesList = commimagesService.LookGoodImages(commodity.getCommid());
commodity.setOtherimg(imagesList);
}
return new ResultVo(true,StatusCode.OK,"查询成功",commodityList);
}else{
return new ResultVo(true,StatusCode.ERROR,"没有相关商品");
}
}
/**
* 首页分类展示商品 --> 按照分类查询商品
List<Collect> collectList = collectService.queryAllCollect((page - 1) * limit, limit, couserid);
Integer dataNumber = collectService.queryCollectCount(couserid);
return new LayuiPageVo("",0,dataNumber,collectList);
}
}
@Controller
public class ChatCtrl {
@Autowired
FriendsService friendsService;
@Autowired
UserInfoService mineService;
@Autowired
ChatmsgService chatmsgService;
/**
* 上传聊天图片
* **/
@PostMapping(value = "/chat/upimg")
//将封装的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){
return new ResultVo(true,StatusCode.LOGINERROR,"用户名不存在");
}catch (IncorrectCredentialsException e){
return new ResultVo(true,StatusCode.LOGINERROR,"密码错误");
}
}
/**重置密码时发送短信验证码
* 1.判断是否为重置密码类型验证码
* 2.判断手机号格式是否正确
* 3.查询账号是否存在
* 4.发送验证码
* */
@ResponseBody
@PostMapping("/user/sendresetpwd")
public ResultVo sendresetpwd(HttpServletRequest request) throws IOException {
JSONObject json = JsonReader.receivePost(request);
final String mobilephone = json.getString("mobilephone");
Integer type = json.getInt("type");
Login login = new Login();
if(type!=1){
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.LOGINERROR,"该用户不存在");
}
String code = GetCode.phonecode();
Integer result = new SmsUtil().SendMsg(mobilephone, code, type);//发送验证码
if(result == 1) {//发送成功
/**发出评论通知消息*/
Notices notices = new Notices().setId(KeyUtil.genUniqueKey()).setUserid(userid2).setTpname("购买")
.setWhys("您的商品 <a href=/product-detail/"+commid+" style=\"color:#08bf91\" target=\"_blank\" >"+commodity.getCommname()+"</a> 被购买了,快去看看吧。");
noticesService.insertNotices(notices);
}
return new ResultVo(true,StatusCode.OK,"操作成功");
}
return new ResultVo(false,StatusCode.ERROR,"操作失败");
}
}
/**
dataNumber = commodityService.queryCommodityCount(userid,null);
}else{
commodityList = commodityService.queryAllCommodity((page - 1) * limit, limit, userid,commstatus);
dataNumber = commodityService.queryCommodityCount(userid,commstatus);
}
return new LayuiPageVo("",0,dataNumber,commodityList);
}
/**
* 个人对商品的操作
* 前端传入商品id(commid)
* 前端传入操作的商品状态(commstatus)-->删除:2 已完成:4
* */
@ResponseBody
@GetMapping("/user/changecommstatus/{commid}/{commstatus}")
public ResultVo ChangeCommstatus( @PathVariable("commid") String commid, @PathVariable("commstatus") Integer commstatus, HttpSession session) {
Integer i = commodityService.ChangeCommstatus(commid, commstatus);
if (i == 1){
/**如果商品已售出*/
// dddd
if (commstatus == 4){
/**查询售出商品的信息*/
Commodity commodity = commodityService.LookCommodity(new Commodity().setCommid(commid));
Soldrecord soldrecord = new Soldrecord();
// String userid1 = (String) session.getAttribute("userid");
String userid2 = (String) commodity.getUserid();
// /**将商品信息添加到售出记录中 —— 买家1*/
// 没有设置买家数据位置,暂时不做功能
// soldrecord.setId(KeyUtil.genUniqueKey()).setCommid(commid).setCommname(commodity.getCommname()).setCommdesc(commodity.getCommdesc())
// .setThinkmoney(commodity.getThinkmoney()).setUserid(userid1);
/**将商品信息添加到售出记录中 —— 卖家2*/
soldrecord.setId(KeyUtil.genUniqueKey()).setCommid(commid).setCommname(commodity.getCommname()).setCommdesc(commodity.getCommdesc())
.setThinkmoney(commodity.getThinkmoney()).setUserid(userid2);
/**添加售出记录*/
soldrecordService.insertSold(soldrecord);
/**发出评论通知消息*/
Notices notices = new Notices().setId(KeyUtil.genUniqueKey()).setUserid(userid2).setTpname("购买")
.setWhys("您的商品 <a href=/product-detail/"+commid+" style=\"color:#08bf91\" target=\"_blank\" >"+commodity.getCommname()+"</a> 被购买了,快去看看吧。");
noticesService.insertNotices(notices);
}
//不能对自己的商品感兴趣
return new ResultVo(false, StatusCode.ERROR,"不能对自己的商品感兴趣");
}
Friends friends=new Friends().setUserid(userid).setFuserid(fuserid);
Integer integer = friendsService.JustTwoUserIsFriend(friends);
if(integer==null){
//如果不存在好友关系插入好友关系
friendsService.insertFriend(friends);
friendsService.insertFriend(new Friends().setFuserid(userid).setUserid(fuserid));
}
return new ResultVo(false, StatusCode.OK,"正在跳转到聊天界面");
}
/**
* TODO 跳转到聊天记录界面
* */
@GetMapping("/tochatlog")
public String tochatlog(){
return "/user/chat/chatlog";
}
/**
* TODO 查询聊天记录
* */
@GetMapping("/chatlog/{uid}")
@ResponseBody
public List<UserInfo> chatlog(@PathVariable("uid")String uid,HttpSession session){
String userid=(String) session.getAttribute("userid");
List<UserInfo> mines = chatmsgService.LookChatMsg(new ChatMsg().setSenduserid(userid).setReciveuserid(uid));
return mines;
}
/**
* TODO 初始化聊天
* */
@GetMapping("/initim")
@ResponseBody
public InitImVo initim(HttpSession session){
String userid = (String) session.getAttribute("userid");
InitImVo initImVo=new InitImVo();
//个人信息
UserInfo mine=friendsService.LookUserMine(userid);
//好友列表
List<UserInfo> list=friendsService.LookUserFriend(userid);
Friend friend=new Friend().setId("2").setGroupname("分组").setList(list);
List<Friend> friendList=new ArrayList<>();
friendList.add(friend);
//群组信息
}
}
@Controller
public class ChatCtrl {
@Autowired
FriendsService friendsService;
@Autowired
UserInfoService mineService;
@Autowired
ChatmsgService chatmsgService;
/**
* 上传聊天图片
* **/
@PostMapping(value = "/chat/upimg")
@ResponseBody
public JSONObject upimg(@RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
JSONObject res = new JSONObject();
JSONObject resUrl = new JSONObject();
String filename = UUID.randomUUID().toString().replaceAll("-", "");
String ext = FilenameUtils.getExtension(file.getOriginalFilename());//获得文件扩展名
Integer i = loginService.updateLogin(new Login().setUserid(userid).setRoleid(roleid));
if (i == 1){
userRoleService.UpdateUserRole(new UserRole().setUserid(userid).setRoleid(1).setIdentity("网站用户"));
/**发出设置为网站用户的系统通知*/
Notices notices = new Notices().setId(KeyUtil.genUniqueKey()).setUserid(userid).setTpname("系统通知")
.setWhys("您已被设置为网站用户,希望您再接再厉。");
noticesService.insertNotices(notices);
return new ResultVo(true, StatusCode.OK, "设置成员成功");
}
return new ResultVo(true, StatusCode.ERROR, "设置成员失败");
}
return new ResultVo(false,StatusCode.ACCESSERROR,"违规操作");
}
/**
* 将用户封号或解封(userstatus)
* 0:封号 1:解封
*/
@PutMapping("/admin/user/forbid/{userid}/{userstatus}")
@ResponseBody
public ResultVo adminuserlist(@PathVariable("userid") String userid,@PathVariable("userstatus") Integer userstatus) {
if (userstatus == 0){
Integer i = loginService.updateLogin(new Login().setUserid(userid).setUserstatus(userstatus));
Integer j = userInfoService.UpdateUserInfo(new UserInfo().setUserid(userid).setUserstatus(userstatus));
if (i ==1 && j == 1){
/**发出封号的系统通知*/
Notices notices = new Notices().setId(KeyUtil.genUniqueKey()).setUserid(userid).setTpname("系统通知")
.setWhys("因为您的不良行为,您在该网站的账号已被封号。");
noticesService.insertNotices(notices);
return new ResultVo(true, StatusCode.OK, "封号成功");
}
return new ResultVo(true, StatusCode.ERROR, "封号失败");
}else if (userstatus == 1){
Integer i = loginService.updateLogin(new Login().setUserid(userid).setUserstatus(userstatus));
Integer j = userInfoService.UpdateUserInfo(new UserInfo().setUserid(userid).setUserstatus(userstatus));
if (i ==1 && j == 1){
/**发出解封的系统通知*/
Notices notices = new Notices().setId(KeyUtil.genUniqueKey()).setUserid(userid).setTpname("系统通知")
.setWhys("您在该网站的账号已被解封,希望您保持良好的行为。");
noticesService.insertNotices(notices);
return new ResultVo(true, StatusCode.OK, "解封成功");
}
return new ResultVo(true, StatusCode.ERROR, "解封失败");
}
return new ResultVo(false,StatusCode.ACCESSERROR,"违规操作");
}
/**
* 管理员商品列表
* */
@GetMapping("/admin/product")
}
}
/**
* <p>
* 收藏控制器
* </p>
*
*/
@Controller
public class CollectController {
@Autowired
private CollectService collectService;
/**
* 商品详情界面:收藏商品or取消收藏
* 前端传入收藏操作(colloperate:1收藏,2取消收藏),获取session中用户id信息,判断是否登录
* (1). 收藏商品
* 1.前端传入商品id(commid)、商品名(commname)、商品描述(commdesc)、商品用户id(cmuserid)
* 商品用户名(username)、商品所在游戏(server)
* 2.session中获取收藏用户id(couserid)
* 3.进行收藏操作
* (2). 取消收藏
* 1.前端传入商品id(commid)
* 2.判断是否本人取消收藏
* 3.进行取消收藏操作
*/
@ResponseBody
@PostMapping("/collect/operate")
public ResultVo insertcollect(@RequestBody Collect collect, HttpSession session){
String couserid = (String) session.getAttribute("userid");
Integer colloperate = collect.getColloperate();
collect.setCouserid(couserid);
String filenames = filename + "." + ext;
file.transferTo(new File("D:\\campusshops\\file\\" + filenames));
resUrl.put("src", "/pic/" + filenames);
resUrl.put("name",file.getOriginalFilename());
res.put("msg", "");
res.put("code", 0);
res.put("data", resUrl);
return res;
}
/**
* 添加好友跳转到个人中心聊天
* */
@PutMapping("/addfrend/{fuserid}")
@ResponseBody
public ResultVo addfrend(@PathVariable("fuserid") String fuserid,HttpSession session){
String userid = (String)session.getAttribute("userid");
if(userid.equals(fuserid)){
//不能对自己的商品感兴趣
return new ResultVo(false, StatusCode.ERROR,"不能对自己的商品感兴趣");
}
Friends friends=new Friends().setUserid(userid).setFuserid(fuserid);
Integer integer = friendsService.JustTwoUserIsFriend(friends);
if(integer==null){
//如果不存在好友关系插入好友关系
friendsService.insertFriend(friends);
friendsService.insertFriend(new Friends().setFuserid(userid).setUserid(fuserid));
}
return new ResultVo(false, StatusCode.OK,"正在跳转到聊天界面");
}
/**
* TODO 跳转到聊天记录界面
* */
@GetMapping("/tochatlog")
public String tochatlog(){
return "/user/chat/chatlog";
}
/**
* TODO 查询聊天记录
* */
@GetMapping("/chatlog/{uid}")
@ResponseBody
Login login = new Login();
UserInfo userInfo = new UserInfo();
login.setUserid(userid);
Login login1 = loginService.userLogin(login);
String oldpwds = new Md5Hash(oldpwd, "Game-shops").toString();
//如果旧密码相等
if (oldpwds.equals(login1.getPassword())){
//盐加密
String passwords = new Md5Hash(newpwd, "Game-shops").toString();
login.setPassword(passwords);
userInfo.setPassword(passwords).setUserid(login1.getUserid());
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.ERROR, "修改密码失败");
}
return new ResultVo(false, StatusCode.LOGINERROR, "当前密码错误");
}
/**
* 展示用户头像昵称
*/
@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;
private UserRoleService userRoleService;
@Autowired
private LoginService loginService;
@Autowired
private UserInfoService userInfoService;
@Autowired
private CommodityService commodityService;
@Autowired
private NoticesService noticesService;
/**
* 管理员跳转登录
*/
@GetMapping("/admin")
public String admintologin() {
return "admin/login/login";
}
/**
* 管理员登录
* 1.判断输入账号的类型
* 2.判断是否为管理员或者超级管理员
* 3.登录
* */
@ResponseBody
@PostMapping("/admin/login")
public ResultVo adminlogin(@RequestBody Login login, HttpSession session){
System.out.println("测试是否进入!!!");
String account=login.getUsername();
String password=login.getPassword();
String vercode=login.getVercode();
UsernamePasswordToken token;
if(!ValidateCode.code.equalsIgnoreCase(vercode)){
return new ResultVo(false,StatusCode.ERROR,"请输入正确的验证码");
}
//判断输入的账号是否手机号
if (!JustPhone.justPhone(account)) {
//输入的是用户名
String username = account;
//盐加密
token=new UsernamePasswordToken(username, new Md5Hash(password,"Game-shops").toString());
}else {
//输入的是手机号
String mobilephone = account;
login.setMobilephone(mobilephone);
//将封装的login中username变为null
login.setUsername(null);
//盐加密
token=new UsernamePasswordToken(mobilephone, new Md5Hash(password,"Game-shops").toString());
}
Subject subject= SecurityUtils.getSubject();
try {