一、项目简述
本系统主要实现的功能有:
网上商城系统,前台+后台管理,用户注册,登录,商品展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
Springboot+ SpringMVC + MyBatis + Jsp + Html+ JavaScript + JQuery + Ajax + maven等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
//执行定时任务
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")
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");
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);
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");
Login login = new Login();
if(type!=0){
return new ResultVo(false,StatusCode.ACCESSERROR,"违规操作");
}
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(result == 1){//发送成功
phonecodemap1.put(mobilephone, code);//放入map集合进行对比
/*
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
* 1.前端传入用户名(username)、密码(password)、邮箱(email)、手机号(mobilephone)、验证码(vercode)
* 2.查询账号是否已经注册
* 3.查询用户名是否已存在
* 4.判断验证码是否有效或正确
* 5.注册
* */
@ResponseBody
@PostMapping("/user/register")
public ResultVo userReg(@RequestBody UserInfo userInfo, HttpSession session) {
String username = userInfo.getUsername();
String password = userInfo.getPassword();
String mobilephone = userInfo.getMobilephone();
String vercode = userInfo.getVercode();
Login login = new Login().setMobilephone(mobilephone);
* 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)){
return new ResultVo(false,StatusCode.ERROR,"请输入正确的验证码");
}
//判断输入的账号是否手机号
if (!JustPhone.justPhone(account)) {
//输入的是用户名
String username = account;
//盐加密
token = new UsernamePasswordToken(username, new Md5Hash(password,"Game-shops").toString());
// System.out.println("1password : "+new Md5Hash(password,"Game-shops").toString());
}else {
((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")
public ResultVo userReg(@RequestBody UserInfo userInfo, HttpSession session) {
String username = userInfo.getUsername();
String password = userInfo.getPassword();
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";
}
/**
* 跳转到完善个人信息
*/
@GetMapping("/user/perfectinfo")
public String perfectInfo(HttpSession session, ModelMap modelMap) {
String userid = (String) session.getAttribute("userid");
UserInfo userInfo = userInfoService.LookUserinfo(userid);
modelMap.put("perfectInfo",userInfo);
return "/user/perfectinfo";
}
/**
return "/admin/index";
}
/**
* 用户登录注册
* */
@GetMapping("/login")
public String login(){
return "/user/logreg";
}
/**
* 用户忘记密码
* */
@GetMapping("/forget")
public String forget(){
return "user/forget";
}
/**
* 个人中心
* */
@GetMapping("/user/center")
public String usercenter(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
String userid = (String) session.getAttribute("userid");
/**拦截器:如果不是用户角色登录,则进行重定向*/
if (StringUtils.isEmpty(userid)){
response.sendRedirect(request.getContextPath() + "/");//重定向
}
public String adminSold(){
return "/admin/sold/soldrecord";
}
/**
* 首页公告清单
* */
@GetMapping("/user/newslist")
public String userNews(){
return "/common/listnews";
}
/**
* 管理员公告列表
* */
@GetMapping("/admin/newslist")
public String adminNews(){
return "/admin/news/newslist";
}
}
个人中心 控制器:
/**
* <p>
* 个人中心 控制器
* </p>
*