Java 文创商城系统的实现流程

一、项目简述

功能:本系统分用户前台和管理员后台。 前台展示+后台管理,前台界面可实现用户登录,用户注 册,商品展示,商品明细展示,用户信息修改,密码修 改,购物车添加,商品购买,商品结算,订单查询,购物 车查询,后台管理可实现商品管理,订单管理,用户管理

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

用户相关接口业务:

/**
 * 用户相关接口
 */
@Controller
@RequestMapping("/index")
public class UserController{

	@Resource
	private UserService userService;
	@Resource
	private OrderService orderService;
	@Resource
	private GoodService goodService;
	@Resource
	private TypeService typeService;
	@Resource
	private ShopcartService shopcartService;
	@Resource
	private SkuService skuService;

	/**
	 * 用户注册
	 * @return
	 */
	@GetMapping("/register")
	public String reg(Model model) {
		model.addAttribute("flag", -1); // 注册页面
		return "/index/register.jsp";
	}

	/**
	 * 用户注册
	 * @return
	 */
	@PostMapping("/register")
	public String register(Users user, Model model){
		if (user.getUsername().isEmpty()) {
			model.addAttribute("msg", "用户名不能为空!");
			return "/index/register.jsp";
		}else if (userService.isExist(user.getUsername())) {
			model.addAttribute("msg", "用户名已存在!");
			return "/index/register.jsp";
		}else {
			String password = user.getPassword();
			userService.add(user);
			user.setPassword(password);
			return "/index/index"; // 注册成功后转去登录
		}
	}

	/**
	 * 用户登录
	 * @return
	 */
	@GetMapping("/login")
	public String log() {
		return "/index/index";
	}

	/**
	 * 用户登录
	 * @return
	 */
	@PostMapping("/login")
	public String login(@RequestParam(required=false, defaultValue="0")int flag, Users user, HttpSession session, Model model) {
		model.addAttribute("typeList", typeService.getList());
		if(flag==-1) {
			flag = 6; // 登录页面
			return "/index/index";
		}
		if(userService.checkUser(user.getUsername(), user.getPassword())){
			Users loginUser = userService.get(user.getUsername());
			session.setAttribute("user", loginUser);
			// 还原购物车数量
			session.setAttribute("total", shopcartService.getTotal(loginUser.getId()));
			return "redirect:index";
		} else {
			model.addAttribute("msg", "用户名或密码错误!");
			return "/index/index";
		}
	}

	/**
	 * 注销登录
	 * @return
	 */
	@RequestMapping("/logout")
	public String logout(HttpSession session) {
		session.removeAttribute("user");
		session.removeAttribute("order");
		return "/index/index";
	}

	/**
	 * 查看购物车
	 * @return
	 */
	@RequestMapping("/shopcart")
	public String shopcart(Model model, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			model.addAttribute("msg", "请先登录!");
			return "/index/index";
		}
		model.addAttribute("typeList", typeService.getList());
		model.addAttribute("shopcartList", shopcartService.getList(user.getId()));
		model.addAttribute("totalPrice", shopcartService.getTotalPrice(user.getId()));
		return "/index/shopcart.jsp";
	}

	/**
	 * 购买
	 * @return
	 */
	@RequestMapping("/buy")
	public @ResponseBody int buy(Shopcart shopcart, HttpSession session, Model model){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return -111;
		}
		shopcart.setUserId(user.getId());
		shopcart.setGood(goodService.get(shopcart.getGoodId()));
		// 验证库存
//		int stock = skuService.getStock(shopcart.getGoodId(), shopcart.getColorId(), shopcart.getSizeId());
//		if(shopcart.getAmount() > stock) {
//			model.addAttribute("msg", "商品 [ " + shopcart.getGood().getName() + " ] 库存不足! 当前库存只有: " + stock);
//		}
		return orderService.save(Arrays.asList(shopcart), user);
	}

	/**
	 * 购买
	 * @return
	 */
	@RequestMapping("/cart")
	public @ResponseBody int cart(Shopcart shopcart, HttpSession session, Model model){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return -111;
		}
		shopcart.setUserId(user.getId());
		shopcartService.save(shopcart);
		int total = shopcartService.getTotal(user.getId());
		session.setAttribute("total", total);
		return total;
	}

	/**
	 * 添加
	 */
	@RequestMapping("/add")
	public @ResponseBody boolean add(int skuid, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return false;
		}
		return shopcartService.add(skuid);
	}

	/**
	 * 减少
	 */
	@RequestMapping("/less")
	public @ResponseBody boolean less(int skuid, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return false;
		}
		return shopcartService.less(skuid);
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public @ResponseBody boolean delete(int skuid, HttpSession session){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return false;
		}
		shopcartService.delete(skuid);
		session.setAttribute("total", shopcartService.getTotal(user.getId()));
		return true;
	}

	/**
	 * 总金额
	 * @return
	 */
	@RequestMapping("/total")
	public @ResponseBody int total(HttpSession session){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			return -111;
		}
		return shopcartService.getTotalPrice(user.getId());
	}

	/**
	 * 提交订单
	 * @return
	 */
	@RequestMapping("/save")
	public String save(ServletRequest request, HttpSession session, Model model){
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			model.addAttribute("msg", "请先登录!");
			return "/index/index";
		}
		List<Shopcart> shopcartList = shopcartService.getList(user.getId());
		if(Objects.isNull(shopcartList) || shopcartList.isEmpty()) {
			model.addAttribute("msg", "购物车没有商品");
			return shopcart(model, session);
		}
		// 验证库存
		for(Shopcart cart : shopcartList) {
			int stock = skuService.getStock(cart.getGoodId(), cart.getColorId(), cart.getSizeId());
			if(cart.getAmount() > stock) {
				model.addAttribute("msg", "商品 [ " + cart.getGood().getName() + " ] 库存不足! 当前库存只有: " + stock);
				return shopcart(model, session);
			}
		}
		int orderid = orderService.save(shopcartList, user);
		if(orderid > 0) {
			// 清空购物车
			session.setAttribute("total", shopcartService.getTotal(user.getId()));
			// 跳转支付
			return "redirect:topay?orderid="+orderid;
		} 

		model.addAttribute("msg", "出了点问题");
		return shopcart(model, session);
	}

	/**
	 * 支付页面
	 * @return
	 */
	@RequestMapping("/topay")
	public String topay(int orderid, ServletRequest request, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
			return "/index/index";
		}
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("order", orderService.get(orderid));
		return "/index/pay.jsp";
	}

	/**
	 * 支付(模拟)
	 * @return
	 */
	@RequestMapping("/pay")
	public String pay(Orders order, ServletRequest request, HttpSession session) {
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			request.setAttribute("msg", "请先登录!");
			return "/index/index";
		}
		// 模拟支付
		orderService.pay(order);
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("order", orderService.get(order.getId()));
		request.setAttribute("msg", "支付成功! 即将跳转到订单列表");
		return "/index/pay.jsp";
	}

	/**
	 * 查看订单
	 * @return
	 */
	@RequestMapping("/order")
	public String order(HttpSession session, Model model){
		model.addAttribute("flag", 12);
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			model.addAttribute("msg", "请登录后查看订单!");
			return "/index/index";
		}
		model.addAttribute("typeList", typeService.getList());
		model.addAttribute("orderList", orderService.getListByUserid(user.getId()));
		return "/index/order.jsp";
	}

	/**
	 * 个人信息
	 * @return
	 */
	@RequestMapping("/my")
	public String my(HttpSession session, Model model){
		model.addAttribute("flag", 11);
		model.addAttribute("typeList", typeService.getList());
		Users user = (Users) session.getAttribute("user");
		if (user == null) {
			model.addAttribute("msg", "请先登录!");
			return "/index/index";
		}
		model.addAttribute("user", user);
		return "/index/my.jsp";
	}

	/**
	 * 修改信息
	 * @return
	 */
	@RequestMapping("/updateUser")
	public String updateUser(Users user, HttpSession session, Model model){
		model.addAttribute("flag", 11);
		model.addAttribute("typeList", typeService.getList());
		Users userLogin = (Users) session.getAttribute("user");
		if (userLogin == null) {
			model.addAttribute("msg", "请先登录!");
			return "/index/index";
		}
		// 修改资料
		Users u = userService.get(userLogin.getId());
		u.setName(user.getName());
		u.setPhone(user.getPhone());
		u.setAddress(user.getAddress());
		userService.update(u);  // 更新数据库
		session.setAttribute("user", u); // 更新session
		model.addAttribute("msg", "信息修改成功!");
		return "/index/my.jsp";
	}

	/**
	 * 修改信息
	 * @return
	 */
	@RequestMapping("/updatePassword")
	public String updatePassword(Users user, HttpSession session, Model model){
		model.addAttribute("flag", 11);
		model.addAttribute("typeList", typeService.getList());
		Users userLogin = (Users) session.getAttribute("user");
		if (userLogin == null) {
			model.addAttribute("msg", "请先登录!");
			return "/index/index";
		}
		// 修改密码
		Users u = userService.get(userLogin.getId());
		if(user.getPasswordNew()!=null && !user.getPasswordNew().trim().isEmpty()) {
			if (user.getPassword()!=null && !user.getPassword().trim().isEmpty()
					&& SafeUtil.encode(user.getPassword()).equals(u.getPassword())) {
				if (user.getPasswordNew()!=null && !user.getPasswordNew().trim().isEmpty()) {
					u.setPassword(SafeUtil.encode(user.getPasswordNew()));
				}
				userService.update(u);  // 更新数据库
				session.setAttribute("user", u); // 更新session
				model.addAttribute("msg", "密码修改成功!");
				return "redirect:logout";
			}else {
				model.addAttribute("msg", "原密码错误!");
			}
		}
		return "/index/index";
	}

}

后台登录验证拦截器:

/**
 * 后台登录验证拦截器
 */
public class AdminInterceptor extends HandlerInterceptorAdapter{

	/**
	 * 检测登录状态
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String uri = request.getRequestURI();
		if(uri.contains("css/") || uri.contains("js/") || uri.contains("img/")
				|| uri.contains("login") || uri.contains("logout")) {
			return true; // 不拦截路径
		}
		Object username = request.getSession().getAttribute("username");
		if (Objects.nonNull(username) && !username.toString().trim().isEmpty()) {
			return true; // 登录验证通过
		}
		response.sendRedirect("login.jsp");
		return false; // 其他情况一律拦截
	}

}

后台相关接口:

/**
 * 后台相关接口
 */
@Controller
@RequestMapping("/admin")
public class AdminController {

	private static final int rows = 10;

	@Autowired
	private AdminService adminService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private UserService userService;
	@Autowired
	private GoodService goodService;
	@Autowired
	private TopService topService;
	@Autowired
	private TypeService typeService;
	@Autowired
	private SkuService skuService;

	/**
	 * 管理员登录
	 * @return
	 */
	@GetMapping("/login")
	public String log() {
		return "/admin/login.jsp";
	}

	/**
	 * 管理员登录
	 * @return
	 */
	@PostMapping("/login")
	public String login(Admins admin, HttpServletRequest request, HttpSession session) {
		if (adminService.checkUser(admin.getUsername(), admin.getPassword())) {
			session.setAttribute("username", admin.getUsername());
			return "redirect:typeList";
		}
		request.setAttribute("msg", "用户名或密码错误!");
		return "/admin/login.jsp";
	}

	/**
	 * 退出
	 * @return
	 */
	@RequestMapping("/logout")
	public String logout(HttpSession session) {
		session.removeAttribute("admin");
		return "/admin/login.jsp";
	}

	/**
	 * 后台首页
	 * @return
	 */
	@RequestMapping("/index")
	public String index(HttpServletRequest request) {
		request.setAttribute("msg", "恭喜你! 登录成功了");
		return "/admin/index.jsp";
	}

	/**
	 * 类目列表
	 *
	 * @return
	 */
	@RequestMapping("/typeList")
	public String typeList(HttpServletRequest request) {
		request.setAttribute("flag", 1);
		request.setAttribute("typeList", typeService.getList());
		return "/admin/type_list.jsp";
	}

	/**
	 * 类目添加
	 *
	 * @return
	 */
	@RequestMapping("/typeAdd")
	public String typeAdd(HttpServletRequest request) {
		request.setAttribute("flag", 1);
		return "/admin/type_add.jsp";
	}

	/**
	 * 类目添加
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/typeSave")
	public String typeSave(Types type, MultipartFile file,
			@RequestParam(required=false, defaultValue="1") int page) throws Exception {
		type.setCover(UploadUtil.upload(file));
		typeService.add(type);
		return "redirect:typeList?flag=1&page="+page;
	}

	/**
	 * 类目更新
	 *
	 * @return
	 */
	@RequestMapping("/typeEdit")
	public String typeEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 1);
		request.setAttribute("type", typeService.get(id));
		return "/admin/type_edit.jsp";
	}

	/**
	 * 类目更新
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/typeUpdate")
	public String typeUpdate(Types type, MultipartFile file,
			@RequestParam(required=false, defaultValue="1") int page) throws Exception {
		if (Objects.nonNull(file) && !file.isEmpty()) {
			type.setCover(UploadUtil.upload(file));
		}
		typeService.update(type);
		return "redirect:typeList?flag=1&page="+page;
	}

	/**
	 * 类目删除
	 *
	 * @return
	 */
	@RequestMapping("/typeDelete")
	public String typeDelete(Types type,
			@RequestParam(required=false, defaultValue="1") int page) {
		typeService.delete(type);
		return "redirect:typeList?flag=1&page="+page;
	}

	/**
	 * sku列表
	 *
	 * @return
	 */
	@RequestMapping("/skuList")
	public String skuList(@RequestParam(required=false, defaultValue="0")byte status, HttpServletRequest request) {
		request.setAttribute("flag", 2);
		request.setAttribute("status", status);
		request.setAttribute("skuList", status>0 ? skuService.getSizeList() : skuService.getColorList());
		return "/admin/sku_list.jsp";
	}

	/**
	 * sku添加
	 *
	 * @return
	 */
	@RequestMapping("/skuSave")
	public String skuSave(String name, int status) {
		if(status > 0) {
			skuService.addSize(name);
		}else {
			skuService.addColor(name);
		}
		return "redirect:skuList?status="+status;
	}

	/**
	 * sku删除
	 *
	 * @return
	 */
	@RequestMapping("/skuDelete")
	public String skuDelete(int id, int status) {
		if(status > 0) {
			skuService.deleteSize(id);
		}else {
			skuService.deleteColor(id);
		}
		return "redirect:skuList?status="+status;
	}

	/**
	 * 产品列表
	 *
	 * @return
	 */
	@RequestMapping("/goodList")
	public String goodList(@RequestParam(required=false, defaultValue="0")byte status, HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		request.setAttribute("flag", 3);
		request.setAttribute("page", page);
		request.setAttribute("status", status);
		request.setAttribute("goodList", goodService.getList(status, page, rows));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, goodService.getTotal(status), page, rows));
		return "/admin/good_list.jsp";
	}

	/**
	 * 产品添加
	 *
	 * @return
	 */
	@RequestMapping("/goodAdd")
	public String goodAdd(HttpServletRequest request) {
		request.setAttribute("flag", 3);
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("colorList", skuService.getColorList());
		request.setAttribute("sizeList", skuService.getSizeList());
		return "/admin/good_add.jsp";
	}

	/**
	 * 产品添加
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/goodSave")
	public String goodSave(Goods good, MultipartFile file,
			@RequestParam(required=false, defaultValue="1") int page) throws Exception {
		good.setCover(UploadUtil.upload(file));
		goodService.add(good);
		return "redirect:goodList?flag=3&page="+page;
	}

	/**
	 * 产品更新
	 *
	 * @return
	 */
	@RequestMapping("/goodEdit")
	public String goodEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 3);
		request.setAttribute("typeList", typeService.getList());
		request.setAttribute("colorList", skuService.getColorList());
		request.setAttribute("sizeList", skuService.getSizeList());
		request.setAttribute("good", goodService.get(id));
		return "/admin/good_edit.jsp";
	}

	/**
	 * 产品更新
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/goodUpdate")
	public String goodUpdate(Goods good, MultipartFile file,
			@RequestParam(required=false, defaultValue="1") int page) throws Exception {
		if (Objects.nonNull(file) && !file.isEmpty()) {
			good.setCover(UploadUtil.upload(file));
		}
		goodService.update(good);
		return "redirect:goodList?flag=3&page="+page;
	}

	/**
	 * 产品删除
	 *
	 * @return
	 */
	@RequestMapping("/goodDelete")
	public String goodDelete(int id,
			@RequestParam(required=false, defaultValue="1") int page) {
		goodService.delete(id);
		return "redirect:goodList?flag=3&page="+page;
	}

	/**
	 * 添加推荐
	 * @return
	 */
	@RequestMapping("/topSave")
	public @ResponseBody String topSave(Tops tops,
			@RequestParam(required=false, defaultValue="0")byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		int id = topService.add(tops);
		return id > 0 ? "ok" : null;
	}

	/**
	 * 删除推荐
	 * @return
	 */
	@RequestMapping("/topDelete")
	public @ResponseBody String topDelete(Tops tops,
			@RequestParam(required=false, defaultValue="0")byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		boolean flag = topService.delete(tops);
		return flag ? "ok" : null;
	}

	/**
	 * 订单列表
	 *
	 * @return
	 */
	@RequestMapping("/orderList")
	public String orderList(@RequestParam(required=false, defaultValue="0")byte status, HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		request.setAttribute("flag", 4);
		request.setAttribute("status", status);
		request.setAttribute("orderList", orderService.getList(status, page, rows));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, orderService.getTotal(status), page, rows));
		return "/admin/order_list.jsp";
	}

	/**
	 * 订单发货
	 *
	 * @return
	 */
	@RequestMapping("/orderDispose")
	public String orderDispose(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.dispose(id);
		return "redirect:orderList?flag=4&status="+status+"&page="+page;
	}

	/**
	 * 订单完成
	 *
	 * @return
	 */
	@RequestMapping("/orderFinish")
	public String orderFinish(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.finish(id);
		return "redirect:orderList?flag=4&status="+status+"&page="+page;
	}

	/**
	 * 订单删除
	 *
	 * @return
	 */
	@RequestMapping("/orderDelete")
	public String orderDelete(int id, byte status,
			@RequestParam(required=false, defaultValue="1") int page) {
		orderService.delete(id);
		return "redirect:orderList?flag=4&status="+status+"&page="+page;
	}

	/**
	 * 顾客管理
	 *
	 * @return
	 */
	@RequestMapping("/userList")
	public String userList(HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		request.setAttribute("flag", 5);
		request.setAttribute("userList", userService.getList(page, rows));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, userService.getTotal(), page, rows));
		return "/admin/user_list.jsp";
	}

	/**
	 * 顾客添加
	 *
	 * @return
	 */
	@RequestMapping("/userAdd")
	public String userAdd(HttpServletRequest request) {
		request.setAttribute("flag", 5);
		return "/admin/user_add.jsp";
	}

	/**
	 * 顾客添加
	 *
	 * @return
	 */
	@RequestMapping("/userSave")
	public String userSave(Users user, HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		if (userService.isExist(user.getUsername())) {
			request.setAttribute("msg", "用户名已存在!");
			return "/admin/user_add.jsp";
		}
		userService.add(user);
		return "redirect:userList?flag=5&page="+page;
	}

	/**
	 * 顾客密码重置页面
	 *
	 * @return
	 */
	@RequestMapping("/userRe")
	public String userRe(int id, HttpServletRequest request) {
		request.setAttribute("flag", 5);
		request.setAttribute("user", userService.get(id));
		return "/admin/user_reset.jsp";
	}

	/**
	 * 顾客密码重置
	 *
	 * @return
	 */
	@RequestMapping("/userReset")
	public String userReset(Users user,
			@RequestParam(required=false, defaultValue="1") int page) {
		String password = SafeUtil.encode(user.getPassword());
		user = userService.get(user.getId());
		user.setPassword(password);
		userService.update(user);
		return "redirect:userList?page="+page;
	}

	/**
	 * 顾客更新
	 *
	 * @return
	 */
	@RequestMapping("/userEdit")
	public String userEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 5);
		request.setAttribute("user", userService.get(id));
		return "/admin/user_edit.jsp";
	}

	/**
	 * 顾客更新
	 *
	 * @return
	 */
	@RequestMapping("/userUpdate")
	public String userUpdate(Users user,
			@RequestParam(required=false, defaultValue="1") int page) {
		userService.update(user);
		return "redirect:userList?flag=5&page="+page;
	}

	/**
	 * 顾客删除
	 *
	 * @return
	 */
	@RequestMapping("/userDelete")
	public String userDelete(Users user,
			@RequestParam(required=false, defaultValue="1") int page) {
		userService.delete(user);
		return "redirect:userList?flag=5&page="+page;
	}

	/**
	 * 管理员列表
	 *
	 * @return
	 */
	@RequestMapping("/adminList")
	public String adminList(HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		request.setAttribute("flag", 6);
		request.setAttribute("adminList", adminService.getList(page, rows));
		request.setAttribute("pageTool", PageUtil.getPageTool(request, adminService.getTotal(), page, rows));
		return "/admin/admin_list.jsp";
	}

	/**
	 * 管理员添加
	 *
	 * @return
	 */
	@RequestMapping("/adminAdd")
	public String adminAdd(HttpServletRequest request) {
		request.setAttribute("flag", 6);
		return "/admin/admin_add.jsp";
	}

	/**
	 * 管理员密码重置
	 *
	 * @return
	 */
	@RequestMapping("/adminRe")
	public String adminRe(int id, HttpServletRequest request) {
		request.setAttribute("flag", 6);
		request.setAttribute("admin", adminService.get(id));
		return "/admin/admin_reset.jsp";
	}

	/**
	 * 管理员密码重置
	 *
	 * @return
	 */
	@RequestMapping("/adminReset")
	public String adminReset(Admins admin, HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		String password = SafeUtil.encode(admin.getPassword());
		admin = adminService.get(admin.getId());
		admin.setPassword(password);
		adminService.update(admin);
		return "redirect:adminList?page="+page;
	}

	/**
	 * 管理员添加
	 *
	 * @return
	 */
	@RequestMapping("/adminSave")
	public String adminSave(Admins admin, HttpServletRequest request,
			@RequestParam(required=false, defaultValue="1") int page) {
		if (adminService.isExist(admin.getUsername())) {
			request.setAttribute("msg", "用户名已存在!");
			return "/admin/admin_add.jsp";
		}
		adminService.add(admin);
		return "redirect:adminList?flag=6&page="+page;
	}

	/**
	 * 管理员修改
	 *
	 * @return
	 */
	@RequestMapping("/adminEdit")
	public String adminEdit(int id, HttpServletRequest request) {
		request.setAttribute("flag", 6);
		request.setAttribute("admin", adminService.get(id));
		return "/admin/admin_edit.jsp";
	}

	/**
	 * 管理员更新
	 *
	 * @return
	 */
	@RequestMapping("/adminUpdate")
	public String adminUpdate(Admins admin,
			@RequestParam(required=false, defaultValue="1") int page) {
		admin.setPassword(SafeUtil.encode(admin.getPassword()));
		adminService.update(admin);
		return "redirect:adminList?flag=6&page="+page;
	}

	/**
	 * 管理员删除
	 *
	 * @return
	 */
	@RequestMapping("/adminDelete")
	public String adminDelete(Admins admin,
			@RequestParam(required=false, defaultValue="1") int page) {
		adminService.delete(admin);
		return "redirect:adminList?flag=6&page="+page;
	}

}

到此这篇关于Java 文创商城系统的实现流程的文章就介绍到这了,更多相关Java 商城系统内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Java 实战项目之学生信息管理系统的实现流程

    一.项目简述 功能包括: 用户的登录注册,学生信息管理,教师信息管理,班级信 息管理,采用mvcx项目架构,覆盖增删改查,包括学生, 教币班级的信息导出上传导入等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuer

  • Java 实战项目之家政服务平台系统的实现流程

    一.项目简述 功能包括: 家政服务网站系统,用户注册,登录,分为家政人员,普 通用户,以及最高管理员,包括家政分类查询,展示,线 上预约服务,家政申请,评论,留言沟通・,联系家政服 务,家政人员的认证,职业认证,以及后台的维护等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis

  • Java 实战项目锤炼之在线蛋糕商城系统的实现

    一.项目简述 功能: 主页显示热销商品:所有蛋糕商品展示,可进行商品搜 索:点击商品进入商品详情页,具有立即购买和加入购物 车功能,可增减购买商品数量亦可手动输入(同时验证库 存),热销商品展示.立即购买进入确认订单页面,可选择 已经添加的地址,亦可新增地址.(同时验证库存),可选 择购买哪些商品,可删除不需要的商品.点击结算进入确 认订单页面,确认后提交订单.后台管理:(修改密码 等),商品管理(商品批量添加.上下架等),订单管理. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.

  • Java 实战项目之教材管理系统的实现流程

    一.项目简述 功能包括: 管理员可以增删改查教材.教材商.入库教材.用户(用 户包括学生和教师)可以对教材商.教材进行.Excel的导入 导出操作.教师以领取入库的教材,可以退还教材.学生只能在对应的教师那里领取教材,并且可以退还教材. 查询自己已经领取的教材.并且对已领教材付款等等. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spr

  • Java 实战项目之毕业设计管理系统的实现流程

    一.项目简述 功能包括: 该系统不错分为学生,教师,管理员,教导主任四种角 色,包括学生管理,教师管理,学生选题,教师选题,主 任审核,管理员审核,开题报告,中期检查,论文提交, 文件管理等等非常不错. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + Ja

  • Java 实战项目锤炼之在线购书商城系统的实现流程

    一.项目简述 功能:一个基于JavaWeb的网上书店的设计与实现,归纳 出了几个模块,首先是登录注册模块,图书查找模块,购 物车模块,订单模块,个人中心模块,用户管理模块,图 书管理模块等. 该项目是javaJeb技术的实战操作,采用了MVC设计模 式,包括基本的entity, jscript, servlet,以及ajax异步请 求,查询分页,持久化层方法的封装等等,对javaweb技 术的巩固很有帮助,为J2EE的学习打下基础,适用于课程 设计,毕业设计. 二.项目运行 环境配置: Jdk1

  • Java 实战交易平台项目之宠物在线商城系统

    该系统分为前台和后台,前台可以自主注册,后台管理员角色,除基础脚手架外,实现的功能有: 后台管理员功能有:商品分类管理.商品管理.套餐管理.新闻分类管理.新闻管理.常见问题.关于我们.团队管理.订单查看和前台用户查看等功能. 前台用户功能有:注册登录.查看商品.购物车.支付订单.评价.照片库.新闻列表.个人中心.购买套餐等功能. 运行环境:windows/Linux均可.jdk1.8.mysql5.7.maven3.5\maven3.6.idea/eclipse均可. 系统控制器代码: /**

  • Java 实战项目之家居购物商城系统详解流程

    一.项目简述 功能: Java Web精品项目源码,家居商城分类展示,商品展示, 商品下单,购物车,个人中心,后台管理,用户管理,商品管理,分类管理等等. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: Jdbc+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload 打开订单列

  • Java 实战项目锤炼之网上商城系统的实现流程

    一.项目简述(+需求文档+PPT) 功能: 主页显示热销商品:所有商品展示,可进行商品搜索:点 击商品进入商品详情页,显示库存,具有立即购买和加入 购物车功能,可增减购买商品数量亦可手动输入(同时验证 库存),热销商品展示.立即购买进入确认订单页面,可选 择已经添加的地址,亦可新增地址.(同时验证库存),可 选择购买哪些商品,可删除不需要的商品.点击结算进入 确认订单页面,确认后提交订单,订单重复提交给予响 应,库存不足或商品下架给予响应.后台管理:(修改密码 等),商品管理(商品批量添加.上下

  • Java 实战范例之校园二手市场系统的实现

    一.项目简述( +IW文档) 功能:本系统分用户前台和管理员后台. 本系统用例模型有三种,分别是游客.注册用户和系统管 理员.下面分别对这三个角色的功能进行描述: 1) 诞 游客是未注册的用户,他们可以浏览物物品,可以搜索物 品,如需购买物品,必须先注册成为网站用户.游客主要 功触吓: a.浏览物品 b.搜索物品 c.注册成为网站用户 2) 注册用户 注册用户是经过网站合法认证的用户,登录网站后可以浏 览物品.搜索物品.发布物品.关注物品.购买物品和查 看个人中心. 3) 系统管理员 系统管理员

随机推荐