基于javaweb+mysql的springboot流浪猫救助系统(java+springboot+ssm+mysql+maven+thymeleaf+html)

基于javaweb+mysql的springboot流浪猫救助系统(java+springboot+ssm+mysql+maven+thymeleaf+html)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

基于javaweb+mysql的SpringBoot流浪猫救助系统(java+springboot+ssm+mysql+maven+thymeleaf+html)

一、项目简述

本系统功能包括:springboot+springmvc+mybatis的流浪 猫救助系统,后台分为普通用户可管理员用,包括注册, 登录,流浪猫发布,评论,分享,后台管理,用户管理, 热门文章赞助等等功能,非常不错,可以以参考二次开发 学习使用。

二、项目运行

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

项目技术: JSP +SpringBoot + MyBatis + Json+ Css + JavaScript + JQuery + Ajax + PageHelper+ Maven等等。

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class SponsorServiceimpl implements SponsorService {
    private static final String POST_CACHE_NAME = "POST2";
    private static final String SPOSORVO_CACHE_NAME = "SPOSORVO";

    @Autowired
    HttpSession session;
    @Autowired
    SponsorMapper sponsorMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    @Cacheable(value = POST_CACHE_NAME, key = "'findPageSponsor'+#page+#limit")
    public PageInfo<Sponsor> findPageSponsorTowrite(int page, int limit) {
        User user= (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        PageHelper.startPage(page,limit);
        return new PageInfo<Sponsor>(sponsorMapper.querySponsorByPhone(user.getUserPhone()));
    }

    @Override
    public int addSponsor(Sponsor sponsor) {
        return sponsorMapper.addSponsor(sponsor);
    }

    @Override
    public void deletesponsor(int sponsorId) {
        sponsorMapper.deleteSponsor(sponsorId);
    }

    @Override
    public Sponsor querySponsorById(int sponsorId) {
        return  sponsorMapper.querySponsorById(sponsorId);
    }

    @Override
    public int updateSponsor(Sponsor sponsor) {
        return sponsorMapper.updateSponsor(sponsor);
    }


@Service
@Transactional(rollbackFor = RuntimeException.class)
public class ShareServiceImpl implements ShareService {

    private static final String POST_CACHE_NAME = "POST";
    private static final String POST_CACHE_NAME_SEARCH = "POST_SEARCH";
    @Autowired
    HttpSession session;
    @Autowired
    ShareMapper shareMapper;

    @Override
    public List<Share> queryShareByPhone(String sharePhone) {
        return shareMapper.queryShareByPhone(sharePhone);
    }

    @Override
    public List<Share> queryShareAll() {
        return shareMapper.queryShareAll();
    }

    @Override
    public List<Share> findindexMaxShare(int limit) {
        return  shareMapper.queryShareMaxCount(limit);
    }

    @Override
    public Share queryShareById(int shareId) {
        return shareMapper.queryShareById(shareId);
    }

    @Override
    public int addShare(Share share) {
        return shareMapper.addShare(share);
    }

                              @RequestParam(value = "page", defaultValue = "1") int page,
                              @RequestParam(value = "limit", defaultValue = "8") int limit,Model model){
        PageInfo<Post> info=postService.findPageSearchPost(page,limit,search);

        model.addAttribute("info",info);
        model.addAttribute("search",search);
        model.addAttribute("indexMax",postService.findMaxPost(4));
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        return "revelation";
    }

    @GetMapping("interceptor/writeRevelation")
    public String write(Model model,HttpSession session,
                        @RequestParam(value = "page", defaultValue = "1") int page,
                        @RequestParam(value = "limit", defaultValue = "10") int limit){
        model.addAttribute("status",0);
        User user = (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        model.addAttribute("info",postService.findPagePost(page,limit));
        return "revelation_writing";
    }

    @GetMapping("interceptor/writeRevelationStatus")
    public String status(@RequestParam("status") int status, Model model,HttpSession session){
        model.addAttribute("status",status);
        if(status==0){
            return "redirect:/revelation/interceptor/writeRevelation";
        }else {
            return "revelation_writing";
        }
    }

    @PostMapping("interceptor/writePost")
    @ResponseBody
    public JsonResult writePost(Post post, HttpSession session){
       User user= (User) session.getAttribute(CatConst.USER_SESSION_KEY);
       post.setPostPhone(user.getUserPhone());
       post.setPostCreatetime(new Date());
       int i=postService.addPost(post);
       if(i==1){
           return new JsonResult(true,"发布成功!");
       }else {
           return new JsonResult(false, "发布失败!");
       }
    }

    @GetMapping("interceptor/deletePost")

@Controller
@RequestMapping("admin/report")
public class adminReportController {

    @Autowired
    ReportService reportService;
    @Autowired
    HttpSession session;
    @Autowired
    ShareService shareService;
    @Autowired
    SponsorService sponsorService;
    @Autowired
    PostService postService;
    @Autowired
    UserService userService;
    @Autowired
    EmailService emailService;

    @GetMapping
    public String report(Model model,
                         @RequestParam(value = "page", defaultValue = "1") int page,
                         @RequestParam(value = "limit", defaultValue = "12") int limit){
        model.addAttribute("info",reportService.findPageReport(page,limit));
        return "admin/admin_report";
    }

    @GetMapping("deleteReport")
    public String deleteReport(int id,String status,int reportId) throws UnsupportedEncodingException, MessagingException {
        System.out.println(id);
        if(status.equals("启示")){
            Post post=postService.queryPostById(id);
            User user=userService.queryByPhone(post.getPostPhone());
            emailService.sendEmail(user.getUserQq()+"@qq.com",post.getPostTitle());
            postService.deletePost(id);

        }if(status.equals("分享")){
            Share share=shareService.queryShareById(id);
            System.out.println(share);
            User user=userService.queryByPhone(share.getSharePhone());
            emailService.sendEmail(user.getUserQq()+"@qq.com",share.getShareTitle());
            shareService.deleteShare(id);

        }if(status.equals("赞助")){
            Sponsor sponsor=sponsorService.querySponsorById(id);
            User user=userService.queryByPhone(sponsor.getSponsorPhone());
            emailService.sendEmail(user.getUserQq()+"@qq.com",sponsor.getSponsorTitle());
            sponsorService.deletesponsor(id);
    SponsorService sponsorService;

    @GetMapping("")
    public String write(Model model, HttpSession session,
                        @RequestParam(value = "page", defaultValue = "1") int page,
                        @RequestParam(value = "limit", defaultValue = "10") int limit){
        model.addAttribute("info",sponsorService.findPagePostSponsorVo(page,limit));
        return "admin/admin_sponsor";
    }

    @GetMapping("adopt")
    public String adopt(@RequestParam("sponsorId") int sponsorId){
        sponsorService.updateSponsorStatus(SponsorStatus.Push.getStatus(),sponsorId);
        return "redirect:/admin/sponsor";
    }

    @GetMapping("repulse")
    public String repulse(@RequestParam("sponsorId") int sponsorId){
        sponsorService.updateSponsorStatus(SponsorStatus.Repulse.getStatus(),sponsorId);
        return "redirect:/admin/sponsor";
    }

    @GetMapping("look")
    public String look(@RequestParam("sponsorId") int sponsorId,Model model){
        Sponsor sponsor=sponsorService.querySponsorById(sponsorId);
        model.addAttribute("sponsor",sponsor);
        return "admin/admin_sponsor_look";
    }

}


@Controller
@RequestMapping("details")
public class detailsController {

    @Autowired
    IndexService indexService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    DetailsService detailsService;
    @Autowired
    PostService postService;
    @Autowired
    SponsorService sponsorService;
    @Autowired
    ShareService shareService;
    @Autowired
    CommentMapper commentMapper;
    @Autowired
    HttpSession session;
    @Autowired
    ReportService reportService;
    @Autowired
    SentenceService sentenceService;

    @GetMapping
    public String index(Model model,Integer id,String status){
        int i=-1;
        if(status.equals(IndexFrom.Post.getDesc())){
            i=0;
        }else if(status.equals(IndexFrom.Share.getDesc())){
            i=1;
        } else if(status.equals(IndexFrom.Sponsor.getDesc())){
            i=2;
        }
        session.setAttribute(CatConst.USER_DETAILS_STATUS,i);
        session.setAttribute(CatConst.USER_DETAILS_CODE,id);
        model.addAttribute("comments",detailsService.findComment(i,id));
        detailsService.addCount(id,i);
        model.addAttribute("count",commentMapper.queryCount1(id,i));
        model.addAttribute("recommends",detailsService.findRecommends(i));
        IndexVo info=detailsService.findDetails(id,i);
        model.addAttribute("info",info);
        model.addAttribute("url",TitleUtil.getUrl());
        List<IndexVo> indexMax=indexService.findMaxCount();

@Controller
@RequestMapping("details")
public class detailsController {

    @Autowired
    IndexService indexService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    DetailsService detailsService;
    @Autowired
    PostService postService;
    @Autowired
    SponsorService sponsorService;
    @Autowired
    ShareService shareService;
    @Autowired
    CommentMapper commentMapper;
    @Autowired
    HttpSession session;
    @Autowired
    ReportService reportService;
    @Autowired
    SentenceService sentenceService;

    @GetMapping
    public String index(Model model,Integer id,String status){
        int i=-1;
        if(status.equals(IndexFrom.Post.getDesc())){
            i=0;
        }else if(status.equals(IndexFrom.Share.getDesc())){
            i=1;
        } else if(status.equals(IndexFrom.Sponsor.getDesc())){
            i=2;
        }
        session.setAttribute(CatConst.USER_DETAILS_STATUS,i);
public class PostServiceImpl implements PostService {
    private static final String POST_CACHE_NAME = "POST";
    private static final String POST_CACHE_NAME_SEARCH = "POST_SEARCH";
    @Autowired
    HttpSession session;
    @Autowired
    PostMapper postMapper;

    @Override
    public List<Post> queryPostByPhone(String postPhone) {
        return postMapper.queryPostByPhone(postPhone);
    }

    @Override
    public List<Post> queryPostAll() {
        return postMapper.queryPostAll();
    }

    @Override
    public Post queryPostById(int postId) {
        return postMapper.queryPostById(postId);
    }

    @Override
    public int addPost(Post post) {
        return postMapper.addPost(post);
    }

    @Override
    public int updatePostCount(int postCount, int postId) {
        return postMapper.updatePostCount(postCount,postId);
    }

    @Override
    public int updatePost(Post post) {
        return postMapper.updatePost(post);
    }

    @Override
    public int deletePost(int postId) {
        return postMapper.deletePost(postId);
    }

    @Override
    @Cacheable(value = POST_CACHE_NAME, key = "'findPagePost'+#page+#limit")
    public PageInfo<Post> findPagePost(int page, int limit) {
        User user= (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        PageHelper.startPage(page,limit);
        return new PageInfo<>(postMapper.queryPostByPhone(user.getUserPhone()));
    }

    @Override

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class SponsorServiceimpl implements SponsorService {
    private static final String POST_CACHE_NAME = "POST2";
    private static final String SPOSORVO_CACHE_NAME = "SPOSORVO";

    @Autowired
    HttpSession session;
    @Autowired
    SponsorMapper sponsorMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    @Cacheable(value = POST_CACHE_NAME, key = "'findPageSponsor'+#page+#limit")
    public PageInfo<Sponsor> findPageSponsorTowrite(int page, int limit) {
        User user= (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        PageHelper.startPage(page,limit);
        return new PageInfo<Sponsor>(sponsorMapper.querySponsorByPhone(user.getUserPhone()));
    }

    @Override
    public int addSponsor(Sponsor sponsor) {
        return sponsorMapper.addSponsor(sponsor);
    }

    @Override
    public void deletesponsor(int sponsorId) {
        sponsorMapper.deleteSponsor(sponsorId);
    }

    @Override
        detailsService.addCount(id,i);
        model.addAttribute("recommends",detailsService.findRecommends(i));
        IndexVo info=detailsService.findDetails(id,i);
        model.addAttribute("info",info);
        List<IndexVo> indexMax=indexService.findMaxCount();
        List<Notice> notices=noticeService.queryNotice();
        model.addAttribute("notices",notices);
        model.addAttribute("indexMax",indexMax);
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        model.addAttribute("url",TitleUtil.getUrl());
        return "details";
    }
}

@Controller
@RequestMapping("")
public class loginController {
    @Autowired
    UserService userService;

    @GetMapping(value = {"/login"})
    public String login(){
        return "login";
    }

    @GetMapping("reBack")
    public String reBack(HttpSession session){
        String url= (String) session.getAttribute("user_old_url");
        if(url==null){
            url="/";
    public String status(@RequestParam("status") int status, Model model,HttpSession session){
        model.addAttribute("status",status);
        if(status==0){
            return "redirect:/revelation/interceptor/writeRevelation";
        }else {
            return "revelation_writing";
        }
    }

    @PostMapping("interceptor/writePost")
    @ResponseBody
    public JsonResult writePost(Post post, HttpSession session){
       User user= (User) session.getAttribute(CatConst.USER_SESSION_KEY);
       post.setPostPhone(user.getUserPhone());
       post.setPostCreatetime(new Date());
       int i=postService.addPost(post);
       if(i==1){
           return new JsonResult(true,"发布成功!");
       }else {
           return new JsonResult(false, "发布失败!");
       }
    }

    @GetMapping("interceptor/deletePost")
    public String deletePost(@RequestParam("postId") int postId){
        postService.deletePost(postId);
        return "redirect:/revelation/interceptor/writeRevelation";
    }

    @GetMapping("interceptor/updatePost")
    public String updatePost(@RequestParam("postId") int postId,Model model){
        Post post=postService.queryPostById(postId);
        System.out.println(post);
        model.addAttribute("post",post);
        model.addAttribute("status",1);
        return "revelation_writing";
    }

    @PostMapping("interceptor/updatePost")
    @ResponseBody
    public JsonResult getUpdatePost(Post post){
        post.setPostCreatetime(new Date());
        int i=postService.updatePost(post);
        if(i==1){
            return new JsonResult(true,"修改成功!");
        }else {
            return new JsonResult(false, "修改失败!");
        }
    @Cacheable(value = ENCLOSURE_CACHE_NAME, key = "'findPageEnclosure'+#page+#limit")
    public PageInfo<Enclosure> findPageEnclosure(int page, int limit) {
        User user= (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        PageHelper.startPage(page,limit);
        return new PageInfo<Enclosure>(enclosureMapper.queryByNumber(user.getUserPhone()));
    }

    @Override
    public int addEnclosure(Enclosure enclosure) {
        return enclosureMapper.addEnclosure(enclosure);
    }

}

@Component
public class LoginInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Object obj = request.getSession().getAttribute(CatConst.USER_SESSION_KEY);
		// 如果user不为空则放行
		if (null != obj) {
			return true;
		}
		// 否则拦截并跳转到登录
		response.sendRedirect("/login");
		return false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}
}


@Component
public class LoginInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Object obj = request.getSession().getAttribute(CatConst.USER_SESSION_KEY);
		// 如果user不为空则放行
		if (null != obj) {
			return true;
		}
		// 否则拦截并跳转到登录
		response.sendRedirect("/login");
		return false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}
}

        comment1.setCommentPhone(user.getUserPhone());
        comment1.setCommentCreatetime(new Date());
        comment1.setCommentPsId(id);
        comment1.setCommentSource(i);
        commentMapper.addComment(comment1);
        model.addAttribute("comments",detailsService.findComment(i,id));
        detailsService.addCount(id,i);
        model.addAttribute("count",commentMapper.queryCount1(id,i));
        model.addAttribute("recommends",detailsService.findRecommends(i));
        IndexVo info=detailsService.findDetails(id,i);
        model.addAttribute("info",info);
        List<IndexVo> indexMax=indexService.findMaxCount();
        List<Notice> notices=noticeService.queryNotice();
        model.addAttribute("notices",notices);
        model.addAttribute("indexMax",indexMax);
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        model.addAttribute("url",TitleUtil.getUrl());
        return "details";
    }

    @PostMapping("interceptor/report")
    public String report(String reason,Model model){
        int i= (int) session.getAttribute(CatConst.USER_DETAILS_STATUS);
        int id= (int) session.getAttribute(CatConst.USER_DETAILS_CODE);
        User user= (User) session.getAttribute("user_session");
        if(reason.equals("")==false){
            Report report=new Report();
            report.setReportUser(user.getUserNickname());
            report.setReportCreatetime(new Date());
            report.setReportContent(reason);
            if(i==0){
                report.setReportFrom("启示");
            }if(i==1){
                report.setReportFrom("分享");
            }if(i==2){
                report.setReportFrom("赞助");
            }
            report.setReportFromId(id);
            reportService.addReport(report);
        }
        model.addAttribute("comments",detailsService.findComment(i,id));
        detailsService.addCount(id,i);
        model.addAttribute("recommends",detailsService.findRecommends(i));
        IndexVo info=detailsService.findDetails(id,i);
        model.addAttribute("info",info);
        List<IndexVo> indexMax=indexService.findMaxCount();
    PostService postService;
    @Autowired
    SponsorService sponsorService;
    @Autowired
    ShareService shareService;
    @Autowired
    CommentMapper commentMapper;
    @Autowired
    HttpSession session;
    @Autowired
    ReportService reportService;
    @Autowired
    SentenceService sentenceService;

    @GetMapping
    public String index(Model model,Integer id,String status){
        int i=-1;
        if(status.equals(IndexFrom.Post.getDesc())){
            i=0;
        }else if(status.equals(IndexFrom.Share.getDesc())){
            i=1;
        } else if(status.equals(IndexFrom.Sponsor.getDesc())){
            i=2;
        }
        session.setAttribute(CatConst.USER_DETAILS_STATUS,i);
        session.setAttribute(CatConst.USER_DETAILS_CODE,id);
        model.addAttribute("comments",detailsService.findComment(i,id));
        detailsService.addCount(id,i);
        model.addAttribute("count",commentMapper.queryCount1(id,i));
        model.addAttribute("recommends",detailsService.findRecommends(i));
        IndexVo info=detailsService.findDetails(id,i);
        model.addAttribute("info",info);
        model.addAttribute("url",TitleUtil.getUrl());
        List<IndexVo> indexMax=indexService.findMaxCount();
        List<Notice> notices=noticeService.queryNotice();
        model.addAttribute("notices",notices);
        model.addAttribute("indexMax",indexMax);
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        return "details";
    }

    @PostMapping("interceptor/addComment")
    public String comment(String comment,Model model){
        int i= (int) session.getAttribute(CatConst.USER_DETAILS_STATUS);
        int id= (int) session.getAttribute(CatConst.USER_DETAILS_CODE);
        User user= (User) session.getAttribute("user_session");
        Comment comment1=new Comment();
        comment1.setCommentContent(comment);
        comment1.setCommentPhone(user.getUserPhone());

@Controller
@RequestMapping("sponsor")
public class sponsorController {
    @Autowired
    SponsorService sponsorService;
    @Autowired
    SentenceService sentenceService;

    @GetMapping("")
    public String sponsor(Model model,HttpSession session,
                          @RequestParam(value = "page", defaultValue = "1") int page,
                          @RequestParam(value = "limit", defaultValue = "8") int limit){
        User user = (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        model.addAttribute("info",sponsorService.findPagePostSponsorse(page,limit));
        model.addAttribute("indexMax",sponsorService.findindexMaxSponsorse(4));
        model.addAttribute("search",null);
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        return "sponsor";
    }

    @GetMapping("interceptor/writeSponsor")
    public String write(Model model,HttpSession session,
                        @RequestParam(value = "page", defaultValue = "1") int page,
                        @RequestParam(value = "limit", defaultValue = "10") int limit){
        model.addAttribute("status",0);
        User user = (User) session.getAttribute(CatConst.USER_SESSION_KEY);
        model.addAttribute("info",sponsorService.findPageSponsorTowrite(page,limit));
        return "sponsor_writing";
    }

    @GetMapping("interceptor/writeSponsorStatus")
    public String status(@RequestParam("status") int status, Model model,HttpSession session){
        model.addAttribute("status",status);
        if(status==0){
            return "redirect:/sponsor/interceptor/writeSponsor";
        }else {
         model.addAttribute("info",info);
         model.addAttribute("search",search);
        List<Notice> notices=noticeService.queryNotice();
        model.addAttribute("notices",notices);
        List<IndexVo> indexMax=indexService.findMaxCount();
        model.addAttribute("indexMax",indexMax);
        return "index";
    }

    @GetMapping("out")
    public String index(){
        session.invalidate();
        return "redirect:";
    }

}

@Controller
@RequestMapping("admin/user")
public class adminUserController {
    @Autowired
    UserService userService;
    @Autowired
    PostMapper postMapper;
    @Autowired

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值