作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
该项目分为前后台,前台普通用户角色,后台管理员角色。
管理员主要功能如下:
登陆,商品分类管理,商品管理,商品订单管理,用户管理等功能。
用户角色主要功能如下:
包含以下功能:查看所有商品,用户登陆注册,按照类别查看商品,发布商品,查看卖家主页,联系卖家,给商品留言,查看订单,修改查看个人资料等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:是;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+BootStrap+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中mybatis.xml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ssm_ershou_shop 登录
运行截图
前台界面
后台界面
相关代码
管理员控制器
@Controller
@RequestMapping(value = "admin")
public class AdminController {
private final UserService userService;
private final GoodService goodService;
private final TypeService typeService;
private final OrderService orderService;
@Autowired
public AdminController(UserService userService, GoodService goodService, TypeService typeService, OrderService orderService) {
this.userService = userService;
this.goodService = goodService;
this.typeService = typeService;
this.orderService = orderService;
}
@RequestMapping(value = "/adminLogin", method = RequestMethod.GET)
public String getAdminLogin(){
return "admin/adminLogin";
}
@RequestMapping(value = "/adminLogin", method = RequestMethod.POST)
public String postAdminLogin(ModelMap model,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "password", required = false) String password,
HttpSession session) {
User admin = userService.getUserByEmail(email);
String message;
if (admin != null){
String mdsPass = DigestUtils.md5DigestAsHex((password + admin.getCode()).getBytes());
// if (!mdsPass .equals(admin.getPassword())){
// message = "用户密码错误!";
// }
if (!password .equals(admin.getPassword())){
message = "用户密码错误!";
} else if (admin.getRoleId() != 101){
message = "用户没有权限访问!";
} else {
session.setAttribute("admin",admin);
return "redirect:/admin/adminPage";
}
} else {
message = "用户不存在!";
}
model.addAttribute("message", message);
return "admin/adminLogin";
}
@RequestMapping(value = "/adminLogout", method = RequestMethod.GET)
public String adminLogout(@RequestParam(required = false, defaultValue = "false" )String adminLogout, HttpSession session){
if (adminLogout.equals("true")){
session.removeAttribute("admin");
}
// adminLogout = "false";
return "redirect:/";
}
@RequestMapping(value = "/adminPage", method = RequestMethod.GET)
public String getAdminPage(ModelMap model,
HttpSession session){
User admin = (User) session.getAttribute("admin");
if (admin == null){
return "redirect:/admin/adminLogin";
}
List<Good> goodList = goodService.getAllGoodList();
for (Good good : goodList) {
good.setGoodUser(userService.getUserById(good.getUserId()));
good.setGoodSecondType(typeService.getSecondTypeById(good.getSecondTypeId()));
}
List<User> userList = userService.getAllUser();
List<FirstType> firstTypeList = typeService.getAllFirstType();
List<Order> orderList = orderService.getOrderList();
model.addAttribute("goodList", goodList);
model.addAttribute("userList", userList);
model.addAttribute("firstTypeList", firstTypeList);
model.addAttribute("orderList", orderList);
return "admin/adminPage";
}
@RequestMapping(value = "/user/update/status/{statusId}&{userId}", method = RequestMethod.GET)
public ResponseEntity updateUserStatus(@PathVariable Integer statusId,
@PathVariable Integer userId){
Boolean success = userService.updateUserStatus(statusId, userId);
if (success){
List<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/delete/{userId}", method = RequestMethod.GET)
public ResponseEntity deleteUser(@PathVariable Integer userId){
Boolean success = userService.deleteUser(userId);
if (success){
List<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
}
首页控制器
@Controller
public class HomeController {
private final UserService userService;
@Autowired
public HomeController(UserService userService) {
this.userService = userService;
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(ModelMap mode, HttpServletRequest request) {
String preURL = request.getHeader("Referer");
mode.addAttribute("preURL", preURL);
return "home/login";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String loginSubmit(ModelMap model,
@RequestParam(value = "preURL", required = false, defaultValue = "") String preURL,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "password", required = false) String password,
HttpSession session) {
User user = userService.getUserByEmail(email);
String message;
if (user != null){
String mdsPass = DigestUtils.md5DigestAsHex((password + user.getCode()).getBytes());
if (!mdsPass .equals(user.getPassword())){
message = "用户密码错误!";
} else {
if (user.getStatusId() == 4){
session.setAttribute("user",user);
if (preURL.equals("")){
return "redirect:/";
} else {
return "redirect:" + preURL;
}
} else {
message = "用户已失效!";
}
}
} else {
message = "用户不存在!";
}
model.addAttribute("message", message);
return "home/login";
}
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(@RequestParam(required = false, defaultValue = "false" )String logout, HttpSession session){
if (logout.equals("true")){
session.removeAttribute("user");
}
return "redirect:/";
}
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String registerPage(ModelMap model) {
User user = new User();
model.addAttribute("user", user);
return "home/register";
}
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerSuccess(ModelMap model,
@Valid User user) {
String status;
Boolean insertSuccess;
InfoCheck infoCheck = new InfoCheck();
if (!infoCheck.isMobile(user.getMobile())){
status = "请输入正确的手机号!";
} else if (!infoCheck.isEmail(user.getEmail())){
status = "请输入正确的邮箱!";
} else if (userService.getUserByMobile(user.getMobile()) != null) {
status = "此手机号码已使用!";
} else if (userService.getUserByEmail(user.getEmail()) != null) {
status = "此邮箱已使用!";
} else if (user.getPassword2() == null){
status = "请确认密码!";
} else {
RandomString randomString = new RandomString();
user.setCode(randomString.getRandomString(5));
String md5Pass = DigestUtils.md5DigestAsHex((user.getPassword() + user.getCode()).getBytes());
user.setPassword(md5Pass);
insertSuccess = userService.registerUser(user);
if (insertSuccess){
return "home/login";
} else {
status = "注册失败!";
model.addAttribute("user", user);
model.addAttribute("status", status);
return "home/register";
}
}
System.out.println(user.getMobile());
System.out.println(status);
model.addAttribute("user", user);
model.addAttribute("status", status);
return "home/register";
}
}
如果也想学习本系统,下面领取。回复:88ssm