我是靠谱客的博主 欣喜书包,最近开发中收集的这篇文章主要介绍Java项目:网上商城系统设计和实现(java+Springboot+ssm+mysql+jsp+maven)源码获取:博客首页 "资源" 里下载!一、项目简述二、项目运行源码获取:博客首页 "资源" 里下载!,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
源码获取:博客首页 "资源" 里下载!
一、项目简述
本系统主要实现的功能有: OnlineMall项目是一套电商系统,包括OnlineMall商城系 统及OnlineMall商城后台管理^统,基于Spring Boot 2.X 及相关技术栈开发。前台商城系统包含首页门户、商品分 类、新品上线、首页轮播、商品推荐、商品搜索、商品展 示、购物车、订单结算、订单流程、个人订单管理、会员 中心、帮助中心等模块。后台管理系统包含数据面板、轮 播图管理、商品管理、订单管理、会员管理、分类管理、 设置等模块。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等
管理员业务控制层:
/**
* 管理员控制层
*/
@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource
private AdminUserService adminUserService;
@GetMapping({"/login"})
public String login() {
return "admin/login";
}
@GetMapping({"/test"})
public String test() {
return "admin/test";
}
@GetMapping({"", "/", "/index", "/index.html"})
public String index(HttpServletRequest request) {
request.setAttribute("path", "index");
request.setAttribute("categoryCount", 0);
request.setAttribute("blogCount", 0);
request.setAttribute("linkCount", 0);
request.setAttribute("tagCount", 0);
request.setAttribute("commentCount", 0);
request.setAttribute("path", "index");
return "admin/index";
}
@PostMapping(value = "/login")
public String login(@RequestParam("userName") String userName,
@RequestParam("password") String password,
@RequestParam("verifyCode") String verifyCode,
HttpSession session) {
if (StringUtils.isEmpty(verifyCode)) {
session.setAttribute("errorMsg", "验证码不能为空");
return "admin/login";
}
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
session.setAttribute("errorMsg", "用户名或密码不能为空");
return "admin/login";
}
String kaptchaCode = session.getAttribute("verifyCode") + "";
if (StringUtils.isEmpty(kaptchaCode) || !verifyCode.equals(kaptchaCode)) {
session.setAttribute("errorMsg", "验证码错误");
return "admin/login";
}
AdminUser adminUser = adminUserService.login(userName, password);
if (adminUser != null) {
session.setAttribute("loginUser", adminUser.getNickName());
session.setAttribute("loginUserId", adminUser.getAdminUserId());
//session过期时间设置为7200秒 即两小时
//session.setMaxInactiveInterval(60 * 60 * 2);
return "redirect:/admin/index";
} else {
session.setAttribute("errorMsg", "登陆失败,请联系作者获得测试账号");
return "admin/login";
}
}
@GetMapping("/profile")
public String profile(HttpServletRequest request) {
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
AdminUser adminUser = adminUserService.getUserDetailById(loginUserId);
if (adminUser == null) {
return "admin/login";
}
request.setAttribute("path", "profile");
request.setAttribute("loginUserName", adminUser.getLoginUserName());
request.setAttribute("nickName", adminUser.getNickName());
return "admin/profile";
}
@PostMapping("/profile/password")
@ResponseBody
public String passwordUpdate(HttpServletRequest request, @RequestParam("originalPassword") String originalPassword,
@RequestParam("newPassword") String newPassword) {
if (StringUtils.isEmpty(originalPassword) || StringUtils.isEmpty(newPassword)) {
return "参数不能为空";
}
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
if (adminUserService.updatePassword(loginUserId, originalPassword, newPassword)) {
//修改成功后清空session中的数据,前端控制跳转至登录页
request.getSession().removeAttribute("loginUserId");
request.getSession().removeAttribute("loginUser");
request.getSession().removeAttribute("errorMsg");
return ServiceResultEnum.SUCCESS.getResult();
} else {
return "修改失败";
}
}
@PostMapping("/profile/name")
@ResponseBody
public String nameUpdate(HttpServletRequest request, @RequestParam("loginUserName") String loginUserName,
@RequestParam("nickName") String nickName) {
if (StringUtils.isEmpty(loginUserName) || StringUtils.isEmpty(nickName)) {
return "参数不能为空";
}
Integer loginUserId = (int) request.getSession().getAttribute("loginUserId");
if (adminUserService.updateName(loginUserId, loginUserName, nickName)) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
return "修改失败";
}
}
@GetMapping("/logout")
public String logout(HttpServletRequest request) {
request.getSession().removeAttribute("loginUserId");
request.getSession().removeAttribute("loginUser");
request.getSession().removeAttribute("errorMsg");
return "admin/login";
}
}
验证码校验控制层:
/**
* 验证码校验控制层
*/
@Controller
public class CommonController {
@Autowired
private DefaultKaptcha captchaProducer;
@GetMapping("/common/kaptcha")
public void defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
byte[] captchaOutputStream = null;
ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();
try {
//生产验证码字符串并保存到session中
String verifyCode = captchaProducer.createText();
httpServletRequest.getSession().setAttribute("verifyCode", verifyCode);
BufferedImage challenge = captchaProducer.createImage(verifyCode);
ImageIO.write(challenge, "jpg", imgOutputStream);
} catch (IllegalArgumentException e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
captchaOutputStream = imgOutputStream.toByteArray();
httpServletResponse.setHeader("Cache-Control", "no-store");
httpServletResponse.setHeader("Pragma", "no-cache");
httpServletResponse.setDateHeader("Expires", 0);
httpServletResponse.setContentType("image/jpeg");
ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream();
responseOutputStream.write(captchaOutputStream);
responseOutputStream.flush();
responseOutputStream.close();
}
@GetMapping("/common/mall/kaptcha")
public void mallKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
com.google.code.kaptcha.impl.DefaultKaptcha newBeeMallLoginKaptcha = new com.google.code.kaptcha.impl.DefaultKaptcha();
Properties properties = new Properties();
properties.put("kaptcha.border", "no");
properties.put("kaptcha.textproducer.font.color", "27,174,171");
properties.put("kaptcha.noise.color", "20,33,42");
properties.put("kaptcha.textproducer.font.size", "30");
properties.put("kaptcha.image.width", "110");
properties.put("kaptcha.image.height", "40");
properties.put("kaptcha.session.key", Constants.MALL_VERIFY_CODE_KEY);
properties.put("kaptcha.textproducer.char.space", "2");
properties.put("kaptcha.textproducer.char.length", "6");
Config config = new Config(properties);
newBeeMallLoginKaptcha.setConfig(config);
byte[] captchaOutputStream = null;
ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();
try {
//生产验证码字符串并保存到session中
String verifyCode = newBeeMallLoginKaptcha.createText();
httpServletRequest.getSession().setAttribute(Constants.MALL_VERIFY_CODE_KEY, verifyCode);
BufferedImage challenge = newBeeMallLoginKaptcha.createImage(verifyCode);
ImageIO.write(challenge, "jpg", imgOutputStream);
} catch (IllegalArgumentException e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
captchaOutputStream = imgOutputStream.toByteArray();
httpServletResponse.setHeader("Cache-Control", "no-store");
httpServletResponse.setHeader("Pragma", "no-cache");
httpServletResponse.setDateHeader("Expires", 0);
httpServletResponse.setContentType("image/jpeg");
ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream();
responseOutputStream.write(captchaOutputStream);
responseOutputStream.flush();
responseOutputStream.close();
}
}
全局异常处理控制层:
/**
* 全局异常处理
*/
@RestControllerAdvice
public class NewBeeMallExceptionHandler {
@ExceptionHandler(Exception.class)
public Object handleException(Exception e, HttpServletRequest req) {
Result result = new Result();
result.setResultCode(500);
//区分是否为自定义异常
if (e instanceof NewBeeMallException) {
result.setMessage(e.getMessage());
} else {
e.printStackTrace();
result.setMessage("未知异常,请联系管理员");
}
//检查请求是否为ajax, 如果是 ajax 请求则返回 Result json串, 如果不是 ajax 请求则返回 error 视图
String contentTypeHeader = req.getHeader("Content-Type");
String acceptHeader = req.getHeader("Accept");
String xRequestedWith = req.getHeader("X-Requested-With");
if ((contentTypeHeader != null && contentTypeHeader.contains("application/json"))
|| (acceptHeader != null && acceptHeader.contains("application/json"))
|| "XMLHttpRequest".equalsIgnoreCase(xRequestedWith)) {
return result;
} else {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("message", e.getMessage());
modelAndView.addObject("url", req.getRequestURL());
modelAndView.addObject("stackTrace", e.getStackTrace());
modelAndView.addObject("author", "十三");
modelAndView.addObject("ltd", "新峰商城");
modelAndView.setViewName("error/error");
return modelAndView;
}
}
}
源码获取:博客首页 "资源" 里下载!
最后
以上就是欣喜书包为你收集整理的Java项目:网上商城系统设计和实现(java+Springboot+ssm+mysql+jsp+maven)源码获取:博客首页 "资源" 里下载!一、项目简述二、项目运行源码获取:博客首页 "资源" 里下载!的全部内容,希望文章能够帮你解决Java项目:网上商城系统设计和实现(java+Springboot+ssm+mysql+jsp+maven)源码获取:博客首页 "资源" 里下载!一、项目简述二、项目运行源码获取:博客首页 "资源" 里下载!所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复