基于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等等。


@Controller
@RequestMapping("admin/sponsor")
public class adminSponsorController {

    @Autowired
    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")
        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")
    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, "修改失败!");

@Controller
@RequestMapping("enclosure")
public class EnclosureController {
    @Autowired
    EnclosureService enclosureService;
    @Autowired
    SentenceService sentenceService;

    @GetMapping("openChoice/{id}")
    public String openChoice(Model model, @PathVariable String id,
                             @RequestParam(value = "page", defaultValue = "1") int page,
                             @RequestParam(value = "limit", defaultValue = "18") int limit) {
        PageInfo<Enclosure> lists = enclosureService.findPageEnclosure(page, limit);
        model.addAttribute("info", lists);
        model.addAttribute("id", id);
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        return "part/open_choice";
    }

    @RequestMapping("upload")
    @ResponseBody
    public JsonResult upload(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request,HttpSession session) {
        return uploadPicture(file,request,session);
    }

    //上传
    public JsonResult uploadPicture(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request,HttpSession session) {
        if (!file.isEmpty()) {
            try {
                // 获取用户目录
                String userPath = System.getProperties().getProperty("user.home") + "/cat/";
                // 保存目录
       }
    }

    @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, "修改失败!");
        }
    }

}

    @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());
        comment1.setCommentCreatetime(new Date());
        comment1.setCommentPsId(id);
        comment1.setCommentSource(i);
        commentMapper.addComment(comment1);

        int i=sponsorService.addSponsor(sponsor);
        if(i==1){
            return new JsonResult(true,"发布成功!");
        }else {
            return new JsonResult(false, "发布失败!");
        }
    }

    @GetMapping("interceptor/deleteSponsor")
    public String deletePost(@RequestParam("sponsorId") int sponsorId){
        sponsorService.deletesponsor(sponsorId);
        return "redirect:/sponsor/interceptor/writeSponsor";
    }

    @GetMapping("interceptor/updateSponsor")
    public String updatePost(@RequestParam("sponsorId") int sponsorId,Model model){
        Sponsor sponsor=sponsorService.querySponsorById(sponsorId);
        model.addAttribute("sponsor",sponsor);
        model.addAttribute("status",1);
        return "sponsor_writing";
    }

    @PostMapping("interceptor/updatePost")
    @ResponseBody
    public JsonResult getUpdatePost(Sponsor sponsor){

        sponsor.setSponsorCreatetime(new Date());
        sponsor.setSponsorStatus(0);
        int i=sponsorService.updateSponsor(sponsor);
        if(i==1){
            return new JsonResult(true,"修改成功!");
        }else {
            return new JsonResult(false, "修改失败!");
        }
    }
    @RequestMapping("Search")
    public String Search(Model model,
                         @RequestParam(value = "page", defaultValue = "1") int page,
                         @RequestParam(value = "limit", defaultValue = "8") int limit,
                       @RequestParam("search") String search ){
        model.addAttribute("search",search);

@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="/";
        }
        return "redirect:"+url;
    }

    @GetMapping(value = {"login1"})
    public String login1(@RequestParam(value ="userUrl") String userUrl,HttpSession session){
        if(userUrl!=null){
            session.setAttribute(CatConst.USER_SESSION_URL,userUrl);
        }
        return "login";
    }

    @PostMapping("login/getLogin")
    @ResponseBody
    public LoginResult getLogin(@RequestParam(value ="phone") String phone,
                                @RequestParam(value ="password") String password, HttpSession session) {
        User user = userService.queryByPhone(phone);
        if(user!=null){
            if(user.getUserPassword().equals(MD5Util.getMD5(password))){
                session.setAttribute(CatConst.USER_SESSION_KEY, user);
                if(user.getUserPhone().equals("admin")){
                    session.setAttribute(CatConst.USER_SESSION_administrators, user.getUserPhone());
                }
                return new LoginResult(true, "登录成功");
            }else {
                return new LoginResult(false, "密码错误");
    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()));

    @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="/";
        }
        return "redirect:"+url;
    }

    @GetMapping(value = {"login1"})
    public String login1(@RequestParam(value ="userUrl") String userUrl,HttpSession session){
        if(userUrl!=null){
            session.setAttribute(CatConst.USER_SESSION_URL,userUrl);
        }
        return "login";
    }

    @PostMapping("login/getLogin")
    @ResponseBody
    public LoginResult getLogin(@RequestParam(value ="phone") String phone,
                                @RequestParam(value ="password") String password, HttpSession session) {
        User user = userService.queryByPhone(phone);
        if(user!=null){
            if(user.getUserPassword().equals(MD5Util.getMD5(password))){
                session.setAttribute(CatConst.USER_SESSION_KEY, user);
                if(user.getUserPhone().equals("admin")){
                    session.setAttribute(CatConst.USER_SESSION_administrators, user.getUserPhone());
                }
                return new LoginResult(true, "登录成功");
            }else {
                return new LoginResult(false, "密码错误");
            }
        }else {
            return new LoginResult(false, "用户名错误");
        }
    }

    @PostMapping("/login/register")
    @ResponseBody
    public JsonResult register(User user,@RequestParam(value ="userCode") String userCode,HttpSession session){
        String code=session.getAttribute(CatConst.USER_SESSION_CODE).toString();
        if(code.equalsIgnoreCase(userCode)){
            if(userService.queryByPhone(user.getUserPhone())!=null){
                return new JsonResult(false, "电话号码已经注册!");
            }else {
                user.setUserPassword(MD5Util.getMD5(user.getUserPassword()));
                user.setUserCreatetime(new Date());
    public PageInfo<Share> findPageSearchShare(int page, int limit, String search) {
        PageHelper.startPage(page,limit);
        String information1="%"+search+"%";
        List<Share> shares=shareMapper.queryShareByTitle(information1);
        return new PageInfo<>(shares);
    }

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

    }
}

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

    @Autowired
    ReportService reportService;
    @Autowired
    HttpSession session;
    @Autowired
    @Cacheable(value = POST_CACHE_NAME_SEARCH, key = "'findPagePostSearch'+#page+#limit+#search")
    public PageInfo<Post> findPageSearchPost(int page, int limit, String search) {
        PageHelper.startPage(page,limit);
        String information1="%"+search+"%";
        List<Post> posts=postMapper.queryPostByTitle(information1);
        return new PageInfo<>(posts);
    }

    @Override
    public List<Post> findMaxPost(int limit) {
        return postMapper.queryPostMaxCount(limit);

    }
}

@Controller
@RequestMapping("")
public class indexController {
    @Autowired
    IndexService indexService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    SentenceService sentenceService;
    @Autowired
    HttpSession session;

@Controller
@RequestMapping("")
public class indexController {
    @Autowired
    IndexService indexService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    SentenceService sentenceService;
    @Autowired
    HttpSession session;

    @GetMapping
    public String index(Model model){
        PageInfo<IndexVo> info=indexService.findPageIndex();
        List<IndexVo> indexMax=indexService.findMaxCount();
        List<Notice> notices=noticeService.queryNotice();
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        model.addAttribute("notices",notices);
        model.addAttribute("search",null);
        model.addAttribute("indexMax",indexMax);
        model.addAttribute("info",info);
        return "index";
    }

    @RequestMapping("indexSearch")
    public String indexSearch(String search,Model model){
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
         PageInfo<IndexVo> info=indexService.findPageIndexSearch(search);
         model.addAttribute("info",info);
         model.addAttribute("search",search);
    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("admin/notice")
public class adminNoticeController {

    @Autowired
    NoticeService noticeService;

    @GetMapping
    public String index(Model model,
                         @RequestParam(value = "page", defaultValue = "1") int page,
                         @RequestParam(value = "limit", defaultValue = "12") int limit){
        model.addAttribute("info",noticeService.findPageNotice(page,limit));
        return "admin/admin_notice";
    }

    @GetMapping("deleteNotice")
    public String deleteNotice(int noticeId){
        noticeService.deleteNotice(noticeId);
        return "redirect:/admin/notice";
    }

    @PostMapping("addNotice")
    @ResponseBody
    public JsonResult writePost(String noticeContent){
        Notice notice=new Notice();
        notice.setNoticeContent(noticeContent);
        notice.setNoticeCreatetime(new Date());
    SentenceService sentenceService;

    @GetMapping("openChoice/{id}")
    public String openChoice(Model model, @PathVariable String id,
                             @RequestParam(value = "page", defaultValue = "1") int page,
                             @RequestParam(value = "limit", defaultValue = "18") int limit) {
        PageInfo<Enclosure> lists = enclosureService.findPageEnclosure(page, limit);
        model.addAttribute("info", lists);
        model.addAttribute("id", id);
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        return "part/open_choice";
    }

    @RequestMapping("upload")
    @ResponseBody
    public JsonResult upload(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request,HttpSession session) {
        return uploadPicture(file,request,session);
    }

    //上传
    public JsonResult uploadPicture(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request,HttpSession session) {
        if (!file.isEmpty()) {
            try {
                // 获取用户目录
                String userPath = System.getProperties().getProperty("user.home") + "/cat/";
                // 保存目录
                StringBuffer hold = new StringBuffer("upload/");
                // 获取时间,以年月创建目录
                Date date = DateUtil.date();
                hold.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth() + 1).append("/");
                File mediaPath = new File(userPath, hold.toString());
                // 如果没有该目录则创建
                if (!mediaPath.exists()) {
                    mediaPath.mkdirs();
                }
                SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
                // 生成文件名称
                String nameSuffix = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."))
                        .replaceAll(" ", "_").replaceAll(",", "") + format.format(DateUtil.date())
                        + new Random().nextInt(1000);
                // 文件后缀
                String fileSuffix = file.getOriginalFilename()
                        .substring(file.getOriginalFilename().lastIndexOf(".") + 1);
                // 上传文件名加后缀
                String fileName = nameSuffix + "." + fileSuffix;

                // 转存文件
                file.transferTo(new File(mediaPath.toString(), fileName));

                // 原图片路径
                StringBuffer originalPath = new StringBuffer();
                originalPath.append(mediaPath.getAbsolutePath()).append("/").append(fileName);
                // 压缩图片路径
        int i=sponsorService.updateSponsor(sponsor);
        if(i==1){
            return new JsonResult(true,"修改成功!");
        }else {
            return new JsonResult(false, "修改失败!");
        }
    }
    @RequestMapping("Search")
    public String Search(Model model,
                         @RequestParam(value = "page", defaultValue = "1") int page,
                         @RequestParam(value = "limit", defaultValue = "8") int limit,
                       @RequestParam("search") String search ){
        model.addAttribute("search",search);
        search="%"+search+"%";
        model.addAttribute("info",sponsorService.findPagePostSponsorseByname(page,limit,search));
        model.addAttribute("indexMax",sponsorService.findindexMaxSponsorse(4));
        Sentence sentence=sentenceService.findSentence();
        model.addAttribute("sentence",sentence);
        return "sponsor";

    }

}


//    有时,一些网站的部分操作需要登录才能访问。如果跳转到登录界面登录成功后,怎样才能返回到登录之前的界面呢?
//    很简单,我们在代码部分中添加一部分很少的代码即可。在从一个页面跳转到登录界面之前的代码,我们用session保
//    存当前界面的url信息,在跳转到登录界面,登录成功后的代码中,判读是否有这个session信息,如果有,则跳转到
//    session所存的url,记住跳转前清空这个session,否则在未关闭浏览器重新登录时可能又会跳到session中所存储url的界面。

}

@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));

@Service
@Transactional(rollbackFor = RuntimeException.class)
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
        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
    public PageInfo<Post> findPageAllPost(int page, int limit) {
        PageHelper.startPage(page,limit);
        return new PageInfo<>(postMapper.queryPostAll());
    }

    @Override
    @Cacheable(value = POST_CACHE_NAME_SEARCH, key = "'findPagePostSearch'+#page+#limit+#search")
    public PageInfo<Post> findPageSearchPost(int page, int limit, String search) {
        PageHelper.startPage(page,limit);
        String information1="%"+search+"%";
        List<Post> posts=postMapper.queryPostByTitle(information1);
        return new PageInfo<>(posts);
    }

    @Override
    public List<Post> findMaxPost(int limit) {
        return postMapper.queryPostMaxCount(limit);

    }

请添加图片描述

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值