当前位置:   article > 正文

基于javaweb+mysql的springboot网上水果超市商城设计和实现(java+ssm+springboot+redis)_水果超市信息管理系统的设计与实现er图

水果超市信息管理系统的设计与实现er图

请添加图片描述
基于javaweb+mysql的springboot网上水果超市商城设计和实现(java+ssm+springboot+redis)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot网上水果超市商城设计和实现(java+ssm+springboot+redis)

主要技术实现:spring、 springmvc、 redis、 springboot、 mybatis 、session、 jquery 、 md5 、bootstarp.js tomcat、、拦截器等。

主要功能实现: 前端:登录、注册、商品分类查看、浏览水果商品、订单管理、发表评论、收藏商品、购物车管理、个人订单管理查看、个人信息查看修改、地址管理等

后台管理员:后台登录、数据统计、系统版本信息等、管理员管理、角色管理、订单管理、通知公告管理、商品种类、和商品详情管理

主要功能截图如下:

用户填写相关信息进行注册:

水果商品数据列表查看:也可以根据关键字搜索水果商品信息

水果商品详情管理:点击可以查看水果商品购买详情数据、可以进行数量操作、加入订单和购物车以及收藏商品和查看排行等功能

我的购物车详情:可以结算以及继续购物和删除购物车信息等操作

订单详情管理:

我的个人信息管理:可以进行密码修改、订单查看管理、收藏查看管理、收获地址管理

我的评论查看:

我的收藏;可以移除收藏

后台管理员端主要实现:

超级管理员admin登录

系统首页:主要功能用户、角色、通知公告信息、商品种类以及商品详情管理和用户管理以及订单信息管理等数据操作。

后台菜单管理:

用户管理:

通知公告列表展示以及内容添加:

后台管理员对水果商品的管理:

上传商品详情信息:

商品评论数据维护:

订单管理和维护:

项目使用eclipse和idea运行、推荐idea、源码架构:

数据库设计ER图:

设计报告:


/**

 */

/**
 * 前台用户管理控制器
 */
@RequestMapping("/home/user")
@Controller
public class HomeUserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IOrderService orderService;

    @Autowired
    private ICommentService commentService;

    /**
     * 注册页面
     * @param model
     * @return
     */
    @RequestMapping(value="/register",method=RequestMethod.GET)
    public String register(Model model) {
        return "home/user/register";
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

/**
 * 后台管理系统菜单控制器

 *
 */
@RequestMapping("/admin/menu")
@Controller
public class MenuController {

	@Autowired
	private IMenuService menuService;
	
	@Autowired 
	private MenuMapper menuMapper;
	
	@Autowired
	private AuthorityMapper authorityMapper;
	
	
	/**
	 * 菜单列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String index(Model model,Integer id,HttpServletRequest request) {
		//获取列表展示有关信息
		List<Menu> allMenus = menuMapper.selectAll();
		model.addAttribute("FirstMenus",menuService.getFirstMenus(allMenus).getData());
		model.addAttribute("SecondMenus",menuService.getSecondMenus(allMenus).getData());
		model.addAttribute("ThirdMenus",menuService.getThirdMenus(allMenus).getData());
		
		//获取路径上有关信息
		Menu selectByPrimaryKey = menuMapper.selectByPrimaryKey(id);
		if(selectByPrimaryKey == null) {
			return "error/404";
		}
		Admin loginedAdmin = (Admin) request.getSession().getAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY);
		List<Authority> selectByRoleId = authorityMapper.selectByRoleId(loginedAdmin.getRoleId()); //获取当前用户所有权限
		Set<Integer> menuIdSet = selectByRoleId.stream().map(Authority :: getMenuId).collect(Collectors.toSet());//把权限中所有菜单id取出来
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

/**

 */

/**
 * 后台管理系统用户控制器

 *
 */
@RequestMapping("/admin/user")
@Controller
public class UserController {

    @Autowired
    private IMenuService menuService;

    @Autowired
    private MenuMapper menuMapper;

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private AuthorityMapper authorityMapper;

    @Autowired
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
     */
    @RequestMapping("/images/{date}/{fileName}")
    public void getIcon(@PathVariable("fileName") String fileName, @PathVariable("date") String date, HttpServletRequest request, HttpServletResponse response) throws IOException {

        if (StringUtils.isEmpty(fileName)) {
            fileName = "";
        }
        String path = uploadPhotoPath + "/" + date + "/" + fileName;
        ;

        File file = new File(path);
        //判断文件是否存在如果不存在就返回默认图标
        if (!(file.exists() && file.canRead())) {
            file = new File(path);
        }

        FileInputStream inputStream = new FileInputStream(file);
        byte[] data = new byte[(int) file.length()];
        int length = inputStream.read(data);
        inputStream.close();
        response.setContentType("image/png");
        OutputStream stream = response.getOutputStream();
        stream.write(data);
        stream.flush();
        stream.close();
    }

    @RequestMapping(value = "/uploadContent.action")
    @ResponseBody
    public void uploadContent(HttpServletRequest request) {
        String content = request.getParameter("myContent");
        System.out.println(content);
        return;
    }
}
package com.demo.controller.admin;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
     * 商品种类列表页面
     * @param model
     * @param id
     * @param request
     * @param content
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value="/index",method= RequestMethod.GET)
    public String index(Model model, Integer id, HttpServletRequest request, String content,
                        @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                        @RequestParam(required = false, defaultValue = "5") Integer pageSize //每页5个数据
    )  {
        //获取列表展示有关信息
        if(StringUtil.isEmpty(content)) {
            //如果查询信息为空
            model.addAttribute("PageInfo", productCategoryService.getProductCategoryByPage(pageNum, pageSize).getData());
        }else {
            model.addAttribute("PageInfo", productCategoryService.getProductCategoryByPageAndContent(pageNum, pageSize, content).getData());
            model.addAttribute("content",content);
        }
        //获取路径上有关信息
        Menu selectByPrimaryKey = menuMapper.selectByPrimaryKey(id);
        if(selectByPrimaryKey == null) {
            return "error/404";
        }
        Admin loginedAdmin = (Admin) request.getSession().getAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY);
        List<Authority> selectByRoleId = authorityMapper.selectByRoleId(loginedAdmin.getRoleId()); //获取当前用户所有权限
        Set<Integer> menuIdSet = selectByRoleId.stream().map(Authority :: getMenuId).collect(Collectors.toSet());//把权限中所有菜单id取出来
        List<Menu> allMenusByStateAndPrimaryKeys = menuMapper.selectByStateAndPrimaryKeys(MenuStateEnum.OPEN.getCode(), menuIdSet);
        model.addAttribute("allAdmins", adminMapper.selectAll());
        model.addAttribute("onThirdMenus", menuService.getThirdMenus(allMenusByStateAndPrimaryKeys).getData());
        model.addAttribute("parentMenu", menuMapper.selectByPrimaryKey(selectByPrimaryKey.getParentId()));
        model.addAttribute("currentMenu", selectByPrimaryKey);
        return "admin/product_category/index";
    }

    /**
     * 商品种类添加页面
     * @param model
     * @return
     */
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

/**
 * 后台管理系统首页控制器

 *
 */
@RequestMapping("/admin/index")
@Controller
public class IndexController {

	@Autowired
	private IMenuService menuService;
	
	@Autowired
	private IAnnouncementService announcementService;
	
	@Autowired 
	private MenuMapper menuMapper;
	
	@Autowired
	private AdminMapper adminMapper;
	
	@Autowired
	private AnnouncementMapper announcementMapper;
	
	@Autowired
	private MailMapper mailMapper;

	@Autowired
	private AttachmentMapper attachmentMapper;
	
	@Autowired
	private AuthorityMapper authorityMapper;

	@Autowired
	private IOrderService orderService;
	
	
	/**
	 * 系统首页页面
	 * @param model
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public ResponseVo<Boolean> delete(Integer id){
		return roleService.delete(id);
	}
	
	
}
package com.demo.controller.admin;

/**
 * 后台管理系统菜单控制器

 *
 */
@RequestMapping("/admin/menu")
@Controller
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
        }
        Admin loginedAdmin = (Admin) request.getSession().getAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY);
        List<Authority> selectByRoleId = authorityMapper.selectByRoleId(loginedAdmin.getRoleId()); //获取当前用户所有权限
        Set<Integer> menuIdSet = selectByRoleId.stream().map(Authority :: getMenuId).collect(Collectors.toSet());//把权限中所有菜单id取出来
        List<Menu> allMenusByStateAndPrimaryKeys = menuMapper.selectByStateAndPrimaryKeys(MenuStateEnum.OPEN.getCode(), menuIdSet);
        model.addAttribute("allAdmins", adminMapper.selectAll());
        model.addAttribute("onThirdMenus", menuService.getThirdMenus(allMenusByStateAndPrimaryKeys).getData());
        model.addAttribute("parentMenu", menuMapper.selectByPrimaryKey(selectByPrimaryKey.getParentId()));
        model.addAttribute("currentMenu", selectByPrimaryKey);
        return "admin/product/index";
    }

    /**
     * 商品添加页面
     * @param model
     * @return
     */
    @RequestMapping(value="/add",method=RequestMethod.GET)
    public String add(Model model) {
        model.addAttribute("productCategoryList", productCategoryMapper.selectAll());
        return "admin/product/add";
    }

    /**
     * 商品编辑页面
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value="/edit",method=RequestMethod.GET)
    public String edit(Model model,Long id) {
        Product selectByPrimaryKey = productMapper.selectByPrimaryKey(id);
        if(selectByPrimaryKey == null) {
            return "error/404";
        }
        model.addAttribute("productCategoryList", productCategoryMapper.selectAll());
        model.addAttribute("Product", selectByPrimaryKey);
        return "admin/product/edit";
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
        }
        //photo.getSize()单位是B
        if (photo.getSize() / 1024 > uploadPhotoMaxSize) {
            CodeMsg codeMsg = CodeMsg.UPLOAD_PHOTO_ERROR;
            codeMsg.setMsg("图片大小不能超过" + (uploadPhotoMaxSize / 1024) + "M");
            return ResponseVo.errorByMsg(codeMsg);
        }
        //准备保存文件
        File filePath = new File(uploadPhotoPath);
        if (!filePath.exists()) {
            //若不存在文件夹,则创建一个文件夹
            filePath.mkdir();
        }
        filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
        //判断当天日期的文件夹是否存在,若不存在,则创建
        if (!filePath.exists()) {
            //若不存在文件夹,则创建一个文件夹
            filePath.mkdir();
        }
        String filename = StringUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + System.currentTimeMillis() + suffix;
        try {
            photo.transferTo(new File(uploadPhotoPath + "/" + filename));   //把文件上传
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename);
        return ResponseVo.success(filename);

    }

    /**
     * 附件统一上传类
     *
     * @param attachment
     * @return
     */
    @RequestMapping(value = "/upload_attachment", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVo<Attachment> uploadAttachment(@RequestParam(name = "attachment", required = true) MultipartFile attachment, HttpServletRequest request) {
        Admin loginedAdmin = (Admin) request.getSession().getAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY);
        String originalFilename = attachment.getOriginalFilename(); //附件名字
        //获取文件后缀
        String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
            }
        }
        //减少商品库存和增加商品销量
        for(OrderItem orderItem : order.getOrderItemList()){
            for(Product product : productList){
                if(orderItem.getProductId().equals(product.getId())){
                   product.setStock(product.getStock() - orderItem.getQuantity());
                   product.setSellNum(product.getSellNum() + orderItem.getQuantity());
                }
            }
        }
        //修改数据库中商品库存和商品销量信息
        for(Product product : productList){
            if(productMapper.updateByPrimaryKeySelective(product) <= 0){
                throw new RuntimeException("商品库存信息更新失败!");
            }
        }
        //修改订单信息
        order.setAddressId(address.getId());
        order.setRemark(remark);
        order.setState(OrderStateEnum.PAYED.getCode());
        //修改数据库中的订单信息
        if(orderMapper.updateByPrimaryKeySelective(order) <= 0){
            throw new RuntimeException("订单提交失败!");
        }
        //清除购物车中选中的商品(redis有事务,但不能回滚,放最后处理)
        HashOperations<String, String, String> opsForHash = redisTemplate.opsForHash();
        String redisKey  = String.format(CART_REDIS_KEY_TEMPLATE, Long.valueOf(uid));
        for(OrderItem orderItem : order.getOrderItemList()){
            String value = opsForHash.get(redisKey, String.valueOf(orderItem.getProductId()));
            //删除商品
            opsForHash.delete(redisKey, String.valueOf(orderItem.getProductId()));
        }
        //发送邮件提醒用户订单提交成功
        //MailUtil.sendMail(MailTypeEnum.ORDER_SUBMIT.getCode(), email, String.valueOf(order.getOrderNo()));
        return ResponseVo.successByMsg(true, "订单提交成功,交易完成!");
    }

    @Override
    public ResponseVo<PageInfo> selectByPageAndUserIdAndIsDeleted(Long userId, Integer isDeleted, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Order> orderList = orderMapper.selectByUserIdAndIsDeleted(userId, isDeleted);
        PageInfo pageInfo = new PageInfo<>(orderList);
        pageInfo.setList(orderList);
        return ResponseVo.success(pageInfo);
    }

    @Override
    public List<Order> selectByOrderStateAndUserIdAndIsDeleted(Integer state, Long userId, Integer isDeleted) {
        return orderMapper.selectByOrderStateAndUserIdAndIsDeleted(state, userId, isDeleted);
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

/**

 */

/**
 * 前台用户管理控制器
 */
@RequestMapping("/home/user")
@Controller
public class HomeUserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IOrderService orderService;

    @Autowired
    private ICommentService commentService;

    /**
     * 注册页面
     * @param model
     * @return
     */
    @RequestMapping(value="/register",method=RequestMethod.GET)
    public String register(Model model) {
        return "home/user/register";
    }

    /**
     * 登录页面
     * @param model
     * @return
     */
    @RequestMapping(value="/login",method=RequestMethod.GET)
    public String login(Model model) {
        return "home/user/login";
    }

    /**
     * 个人信息页面
     * @param model
     * @return
     */
    @RequestMapping(value="/info",method=RequestMethod.GET)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
            }
        }
        //修改订单信息
        order.setAddressId(address.getId());
        order.setRemark(remark);
        order.setState(OrderStateEnum.PAYED.getCode());
        //修改数据库中的订单信息
        if(orderMapper.updateByPrimaryKeySelective(order) <= 0){
            throw new RuntimeException("订单提交失败!");
        }
        //清除购物车中选中的商品(redis有事务,但不能回滚,放最后处理)
        HashOperations<String, String, String> opsForHash = redisTemplate.opsForHash();
        String redisKey  = String.format(CART_REDIS_KEY_TEMPLATE, Long.valueOf(uid));
        for(OrderItem orderItem : order.getOrderItemList()){
            String value = opsForHash.get(redisKey, String.valueOf(orderItem.getProductId()));
            //删除商品
            opsForHash.delete(redisKey, String.valueOf(orderItem.getProductId()));
        }
        //发送邮件提醒用户订单提交成功
        //MailUtil.sendMail(MailTypeEnum.ORDER_SUBMIT.getCode(), email, String.valueOf(order.getOrderNo()));
        return ResponseVo.successByMsg(true, "订单提交成功,交易完成!");
    }

    @Override
    public ResponseVo<PageInfo> selectByPageAndUserIdAndIsDeleted(Long userId, Integer isDeleted, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Order> orderList = orderMapper.selectByUserIdAndIsDeleted(userId, isDeleted);
        PageInfo pageInfo = new PageInfo<>(orderList);
        pageInfo.setList(orderList);
        return ResponseVo.success(pageInfo);
    }

    @Override
    public List<Order> selectByOrderStateAndUserIdAndIsDeleted(Integer state, Long userId, Integer isDeleted) {
        return orderMapper.selectByOrderStateAndUserIdAndIsDeleted(state, userId, isDeleted);
    }

    @Override
    public ResponseVo<Boolean> updateOrderState(Long orderId, Integer state) {
        if(orderId == null || state == null){
            return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
        }
        Order order = orderMapper.selectByPrimaryKey(orderId);
        if(order == null){
            return ResponseVo.errorByMsg(CodeMsg.ORDER_NOT_EXIST);
        }
        if(orderMapper.updateStateByOrderId(orderId, state) <= 0){
            return ResponseVo.errorByMsg(CodeMsg.ORDER_STATE_EDIT_ERROR);
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

/**

 */

/**
 * 用户service接口实现类

 *
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public ResponseVo<Boolean> isUsernameExist(User user, Long id) {
        User findByUsername = userMapper.findUserByUsername(user.getUsername());
        if(findByUsername != null) {
            if(!findByUsername.getId().equals(id)) {
                return ResponseVo.success(true); //出现重名
            }
        }
        return ResponseVo.success(false);//没有重名
    }

    @Override
    public ResponseVo<Boolean> login(String username, String password) {
        //判断用户输入的用户名称是否为空
        if(StringUtil.isEmpty(username)){
            return ResponseVo.errorByMsg(CodeMsg.USER_USERNAME_EMPTY);
        }
        //判断用户输入的密码是否为空
        if(StringUtil.isEmpty(password)){
            return ResponseVo.errorByMsg(CodeMsg.USER_PASSWORD_EMPTY);
        }
        //判断用户是否存在
        User findUser = userMapper.findUserByUsername(username);
        if(findUser == null){
            return ResponseVo.errorByMsg(CodeMsg.USER_NOT_EXIST);
        }
        //判断用户输入的信息是否正确
        if(!password.equals(findUser.getPassword())){
            return ResponseVo.errorByMsg(CodeMsg.USERNAME_OR_PASSWORD_ERROR);
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
						e3.printStackTrace();
					}
					return false;
				}
			}
		}
		return true;
	}
}
package com.demo.controller.admin;

/**
 * 后台管理系统首页控制器

 *
 */
@RequestMapping("/admin/index")
@Controller
public class IndexController {

	@Autowired
	private IMenuService menuService;
	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

}
package com.demo.controller.common;

/**
 * 公用的上传类
 */
@RequestMapping("/upload")
@Controller
public class UploadController {

    private String uploadPhotoSufix = ".jpg,.png,.gif,.jpeg";

    private long uploadPhotoMaxSize = 10240;   //大小1024KB

    private String uploadPhotoPath = System.getProperty("user.dir") + "/src/main/resources/upload/photo/";

    private long uploadAttachmentMaxSize = 204800;   //大小204800KB

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
	 * @param cpacha
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.POST)
	@ResponseBody
	public ResponseVo<Boolean> login(Admin admin, String cpacha, HttpServletRequest request){
		if(admin == null) {
			return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
		}
		if(StringUtil.isEmpty(cpacha)) {
			return ResponseVo.errorByMsg(CodeMsg.CPACHA_EMPTY);
		}
		String correct_cpacha = (String) request.getSession().getAttribute("admin_login");
		//判断验证码是否过期
		if(StringUtil.isEmpty(correct_cpacha)){
			return ResponseVo.errorByMsg(CodeMsg.CPACHA_EXPIRE);
		}
		if(!cpacha.toLowerCase().equals(correct_cpacha.toLowerCase())) {
			return ResponseVo.errorByMsg(CodeMsg.CPACHA_ERROR);
		}
		//去数据库查询数据验证
		Admin selectByNameAndPassword = adminMapper.selectByNameAndPassword(admin.getName(), admin.getPassword());
		if(selectByNameAndPassword == null) {
			return ResponseVo.errorByMsg(CodeMsg.USERNAME_OR_PASSWORD_ERROR);
		}
		//验证该用户是否被冻结
		if(selectByNameAndPassword.getState().intValue() == AdminStateEnum.STOP.getCode().intValue()) {
			return ResponseVo.errorByMsg(CodeMsg.USER_STATE_ERROR);
		}
		//验证该用户是否无权限
		List<Authority> selectByRoleId = authorityMapper.selectByRoleId(selectByNameAndPassword.getRoleId());
		if(selectByRoleId == null || selectByRoleId.size() == 0) {
			return ResponseVo.errorByMsg(CodeMsg.USER_AUTHORITY_ERROR);
		}
		//创建权限
		request.getSession().setAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY, selectByNameAndPassword);
		return ResponseVo.success(true);
	}
	

	@RequestMapping(value="/save_person_info",method=RequestMethod.POST)
	@ResponseBody
	public ResponseVo<Boolean> savePersonInfo(Admin admin,HttpServletRequest request){
		if(admin == null) {
			return ResponseVo.errorByMsg(CodeMsg.DATA_ERROR);
		}
		Admin loginedAdmin = (Admin) request.getSession().getAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY);
		BeanUtils.copyProperties(admin, loginedAdmin, "id","createTime","updateTime","roleId","state");
		if(adminMapper.updateByPrimaryKeySelective(loginedAdmin) <= 0) {
			return ResponseVo.errorByMsg(CodeMsg.PERSON_INFO_SAVE_ERROR);
		}
		//更新权限
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
		List<Authority> selectByRoleId = authorityMapper.selectByRoleId(loginedAdmin.getRoleId()); //获取当前用户所有权限
		Set<Integer> menuIdSet = selectByRoleId.stream().map(Authority :: getMenuId).collect(Collectors.toSet());//把权限中所有菜单id取出来
		List<Menu> allMenusByStateAndPrimaryKeys = menuMapper.selectByStateAndPrimaryKeys(MenuStateEnum.OPEN.getCode(), menuIdSet);
		model.addAttribute("onThirdMenus", menuService.getThirdMenus(allMenusByStateAndPrimaryKeys).getData());
		model.addAttribute("parentMenu", menuMapper.selectByPrimaryKey(selectByPrimaryKey.getParentId()));
		model.addAttribute("currentMenu", selectByPrimaryKey);
		return "admin/admin/index";
	}
	
	/**
	 * 管理员添加页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model) {
		model.addAttribute("RoleList", roleMapper.selectAll());
		return "admin/admin/add";
	}
	
	/**
	 * 管理员编辑页面
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(Model model,Integer id) {
		Admin selectByPrimaryKey = adminMapper.selectByPrimaryKey(id);
		if(selectByPrimaryKey == null) {
			return "error/404";
		}
		model.addAttribute("RoleList", roleMapper.selectAll());
		model.addAttribute("editAdmin", selectByPrimaryKey);
		return "admin/admin/edit";
	}
	
	/**
	 * 管理员添加表单处理
	 * @param admin
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

/**
 * 公用的上传类
 */
@RequestMapping("/upload")
@Controller
public class UploadController {

    private String uploadPhotoSufix = ".jpg,.png,.gif,.jpeg";

    private long uploadPhotoMaxSize = 10240;   //大小1024KB

    private String uploadPhotoPath = System.getProperty("user.dir") + "/src/main/resources/upload/photo/";

    private long uploadAttachmentMaxSize = 204800;   //大小204800KB

    private String uploadAttachmentPath = System.getProperty("user.dir") + "/src/main/resources/upload/attachment/";

    private Logger log = LoggerFactory.getLogger(UploadController.class);

    @Autowired
    private AttachmentMapper attachmentMapper;

    /**
     * 图片统一上传类
     *
     * @param photo
     * @return
     */
    @RequestMapping(value = "/upload_photo", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVo<String> uploadPhoto(@RequestParam(name = "photo", required = true) MultipartFile photo) {
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/586845
推荐阅读
相关标签
  

闽ICP备14008679号