基于SSM+SpringBoot+MySQL+Bootstrap的在线动漫系统

分类

历史记录

个人信息

在线动漫登陆

首页

基础信息

添加图片

上传

分类

开发工具: Idea/Eclipse
数据库: mysql
Jar包仓库: Maven
前段框架: bootstrap
后端框架: Spring+SpringMVC+Mybatis+SpringBoot


@Controller
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private UserService userService;
    @Autowired
    private HttpServletRequest request;

    @RequestMapping("/login")
    public String login(Model model,String username, String password) {
        if (userService.login(username,password)) {
            HttpSession session = request.getSession();
            User user = userService.findUserByUserName(username);
            session.setAttribute("userId",user.getId());
            return "redirect:/upload/toUploadManage";
        } else {
            model.addAttribute("msgErrorFlag", false);
            model.addAttribute("errorMsg", "用户名或密码出错");
            return "index2";
        }

    }

    @RequestMapping("/regist")
    public String regist(Model model, String userName, String password, String realName, String idCard, String phone, String email) {
        User user = userService.regist(model,userName, password, realName, idCard, phone, email);
        Object errorMsg = model.getAttribute("errorMsg");
        if (errorMsg != null) {
            return "/userPage/regist";
        }
        return "index2";
    }

    @RequestMapping("/modifyPwd")
    @ResponseBody
    public String modifyPwd(String oldPwd, String newPwd) {
        HttpSession session = request.getSession();
        Long userId = (Long)session.getAttribute("userId");
        if (userId!=null){
        }else {
            JSONObject result = new JSONObject();
            result.put("status","error");
            result.put("msg","无法获取用户id");
            return result.toJSONString();
        }
        User user = userService.findUserById(userId);
        oldPwd = DigestUtils.md5DigestAsHex(oldPwd.getBytes());
        if (oldPwd!=null && user.getPassword().equals(oldPwd)){
        }else {
            JSONObject result = new JSONObject();
            result.put("status","error");
            result.put("msg","旧密码错误");
            return result.toJSONString();
        }
        if (newPwd!=null && !"".equals(newPwd)){
            newPwd = DigestUtils.md5DigestAsHex(newPwd.getBytes());
            user.setPassword(newPwd);
            userService.modify(user);
        }else {
            JSONObject result = new JSONObject();
            result.put("status","error");
            result.put("msg","新密码格式非法");
            return result.toJSONString();
        }
        JSONObject result = new JSONObject();
        result.put("status", "success");
        result.put("msg", "修改成功");
        return result.toJSONString();
    }

    @RequestMapping("/toLogin")
    public String toLogin() {
        return "index2";
    }

    @RequestMapping("/toRegist")
    public String toRegist(){ return "/userPage/regist"; }
    @RequestMapping("/toUploadImgFile")
    public String toUploadImgFile(){return "/userManage/comicUploadManage";}
    @RequestMapping("/toModifyPwd")
    public String toModifyPwd(){
        return "userPage/modifyPwd";
    }
}

@Controller
@RequestMapping("/comic")
public class ComicController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private ClassfiyService classfiyService;
    @Autowired
    private AddressService addressService;
    @Autowired
    private ProgressService progressService;
    @Autowired
    private ComicService comicService;
    @Autowired
    private ComicDetailService comicDetailService;
    @Autowired
    private ComicCollectService comicCollectService;
    @Autowired
    private ComicHistoryService comicHistoryService;


    @RequestMapping("/toComicShow")
    public String toComicShow(Model model,Long comicId){
        if (!checkIsLogin()){
            return "redirect:/user/toLogin";
        }
        //comicId = 2L;
        HttpSession session = request.getSession();
        Long userId = (Long)session.getAttribute("userId");
        Comic comic = comicService.findComicById(comicId);
        Comic comicCopy = new Comic();
        BeanUtils.copyProperties(comic,comicCopy);
        ComicCollect comicCollect = comicCollectService.findComicCollectByUserIdAndComicId(userId, comicId);
        comicCopy.setAddress(addressService.findByIdReturnName(Long.valueOf(comic.getAddress())));
        comicCopy.setProgress(progressService.findByIdReturnName(Long.valueOf(comic.getProgress())));
        comicCopy.setClassfiy(classfiyService.findByIdReturnName(Long.valueOf(comic.getClassfiy())));
        ComicHistory comicHistory = comicHistoryService.findComicHistoryByUserIdAndComicId(userId, comicId);
        comicHistory = this.checkComicHistory(comicHistory,comic,userId);
        comicHistoryService.saveComicHistory(comicHistory);
        model.addAttribute("comic",comicCopy);
        model.addAttribute("comicCollect",comicCollect);
        model.addAttribute("comicHistory",comicHistory);

        return "/comicMainPage/comicShow";
    }
    @RequestMapping("/toClassfiy")
    public String toClassfiy(Model model,
     @RequestParam(value = "classfiyId",defaultValue = "0") Long classfiyId,
     @RequestParam(value = "addressId",defaultValue = "0") Long addressId,
     @RequestParam(value = "progressId",defaultValue = "0") Long progressId,
     @RequestParam(value = "pageNumber",defaultValue = "0") Integer pageNumber ){
        if (!checkIsLogin()){
            return "redirect:/user/toLogin";
        }
        this.getAllClassifyAddressProgress(model);
        this.checkSelectedTagAndAdd(model,classfiyId,addressId,progressId);
        Comic comic = new Comic();
        comic.setClassfiy(Long.toString(classfiyId));
        comic.setAddress(Long.toString(addressId));
        comic.setProgress(Long.toString(progressId));
        Page<Comic> comicPage;
        if(pageNumber > 0){
            comicPage = comicService.findByCondition(pageNumber-1, comic);
        }else {
            comicPage = comicService.findByCondition(0, comic);
        }
        List<Comic> comicList = comicPage.getContent();
        model.addAttribute("comicList",comicList);
        model.addAttribute("page",comicPage);
        model.addAttribute("currentPage",pageNumber);
        return "/comicMainPage/classify";
    }
    @RequestMapping("/toSearch")
    public  String toSearch(Model model,String searchInfo,
    @RequestParam(value = "classfiyId",defaultValue = "0") Long classfiyId,
    @RequestParam(value = "addressId",defaultValue = "0") Long addressId,
    @RequestParam(value = "progressId",defaultValue = "0") Long progressId,
    @RequestParam(value = "pageNumber",defaultValue = "0") Integer pageNumber){
        if (!checkIsLogin()){
            return "redirect:/user/toLogin";
        }
        this.getAllClassifyAddressProgress(model);
        this.checkSelectedTagAndAdd(model,classfiyId,addressId,progressId);
        Comic comic = new Comic();
        if(searchInfo != null && !"".equals(searchInfo)){
            comic.setTitle(searchInfo);
        }
        comic.setClassfiy(Long.toString(classfiyId));
        comic.setAddress(Long.toString(addressId));
        comic.setProgress(Long.toString(progressId));
        Page<Comic> comicPage;
        if(pageNumber > 0){
            comicPage = comicService.findByCondition(pageNumber-1, comic);
        }else {
            comicPage = comicService.findByCondition(0, comic);
        }
        List<Comic> comicList = comicPage.getContent();
        model.addAttribute("searchInfo", searchInfo);
        model.addAttribute("comicList",comicList);
        model.addAttribute("page",comicPage);
        model.addAttribute("currentPage",pageNumber);
        return "/comicMainPage/search";
    }

    @RequestMapping("/toComicMain")
    public String toComicMain(Model model) {
        if (!checkIsLogin()){
            return "redirect:/user/toLogin";
        }
        List<Long> recomendComicId = JSON.parseArray(GlobalConstants.RECOMMEND_COMIC,Long.class);
        List<Long> carouselRecomendComicId = JSON.parseArray(GlobalConstants.CAROUSEL_RECOMMEND_COMIC,Long.class);
        List<Comic> recomendComic = new ArrayList<>();
        List<Comic> carouselRecomendComic = new ArrayList<>();
        List<Comic> rankComic = new ArrayList<>();
        for (Long id : recomendComicId){
            Comic comic = new Comic();
            comic = comicService.findComicById(id);
            recomendComic.add(comic);
        }
        for (Long id : carouselRecomendComicId){
            Comic comic = new Comic();
            comic = comicService.findComicById(id);
            carouselRecomendComic.add(comic);
        }
        List<Long> comicRankId = comicCollectService.getComicRank();
        for (Long id : comicRankId){
            Comic comic = new Comic();
            comic = comicService.findComicById(id);
            rankComic.add(comic);
        }
        model.addAttribute("comicList",recomendComic);
        model.addAttribute("carouselComicList",carouselRecomendComic);
        model.addAttribute("rankComicList",rankComic);
        this.getAllClassifyAddressProgress(model);
        return "/comicMainPage/comicMain";
    }

    @RequestMapping("/addComicCollect")
    @ResponseBody
    public String addComicCollect(Long comicId){
        HttpSession session = request.getSession();
        Long userId = (Long)session.getAttribute("userId");
        ComicCollect comicCollect = comicCollectService.findComicCollectByUserIdAndComicId(userId, comicId);
        JSONObject result = new JSONObject();
        if(comicCollect != null){
            comicCollectService.deleteComicCollectById(comicCollect.getId());
            result.put("msg", "取消收藏");
            result.put("isCollect", "收藏");
        }else {
            comicCollect = new ComicCollect();
            comicCollect.setComicId(comicId);
            comicCollect.setUserId(userId);
            comicCollectService.saveComicCollect(comicCollect);
            result.put("msg", "收藏成功");
            result.put("isCollect", "已收藏");
        }
        return result.toJSONString();
    }

    @RequestMapping("/updateHistory")
    @ResponseBody
    public String updateHistory(Long comicId, Long comicDetailId) {
        JSONObject result = new JSONObject();
        HttpSession session = request.getSession();
        ComicHistory comicHistory = null;
        Long userId = (Long)session.getAttribute("userId");
        if (comicId != null){
            comicHistory = comicHistoryService.findComicHistoryByUserIdAndComicId(userId, comicId);
            Comic comic = new Comic();
            comic.setId(comicId);
            if (comicDetailId != null){
                ComicDetail comicDetail = comicDetailService.findComicDetailByIdAndComicId(comicDetailId, comic);
                if (comicDetail!=null){
                    comicHistory.setUpdateTime(new Date());
                    comicHistory.setComicDetailId(comicDetailId);
                    result.put("msg", "历史添加成功");
                    result.put("comicHistory", comicHistory);
                    comicHistoryService.saveComicHistory(comicHistory);
                    return result.toJSONString();
                }
            }
        }
        result.put("msg", "历史添加失败");
        result.put("comicHistory", comicHistory);
        comicHistoryService.saveComicHistory(comicHistory);
        return result.toJSONString();
    }
    public boolean checkIsLogin(){
        HttpSession session = request.getSession();
        Object userId = session.getAttribute("userId");
        Long id = (Long) userId;
        if(id!=null){
            return true;
        }
        return false;
    }
    public ComicHistory checkComicHistory(ComicHistory comicHistory,Comic comic,Long userId){
        if(comicHistory != null){
            comicHistory.setUpdateTime(new Date());
        }else {
            comicHistory = new ComicHistory(userId,comic.getId(),new Date());
            comicHistory.setUpdateTime(new Date());
        }
        Long comicDetailId = comicHistory.getComicDetailId();
        if (comicDetailId != null) {
            ComicDetail comicDetailByIdAndComicId = comicDetailService.findComicDetailByIdAndComicId(comicDetailId, comic);
            if (comicDetailByIdAndComicId != null){
                return comicHistory;
            }
        }
        List<ComicDetail> comicDetailList = comic.getComicDetailList();
        Long detailId = null;
        if (comicDetailList != null && comicDetailList.size()>0){
            detailId=comicDetailList.get(0).getId();
        }
        comicHistory.setComicDetailId(detailId);
        return comicHistory;
    }
    public void getAllClassifyAddressProgress(Model model){
        List<Classfiy> classfiyList = classfiyService.findAll();
        List<Address> addressList = addressService.findAll();
        List<Progress> progressesList = progressService.findAll();

        model.addAttribute("classfiyList",classfiyList);
        model.addAttribute("addressList",addressList);
        model.addAttribute("progressesList",progressesList);
    }
    public void checkSelectedTagAndAdd(Model model,Long classId,Long addressId,Long progressId){
        model.addAttribute("classId",classId);
        model.addAttribute("addressId",addressId);
        model.addAttribute("progressId",progressId);

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

2016855150

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值