• Java项目:ssm流浪狗领养系统


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    流浪狗领养网站是一个基于ssm(Spring SpringMVC MyBatis)的项目,项目分为前后台。
    前台网站主要首页(包含轮播图、关键字搜索、点击排行、最新文章、站长推荐、最新评论、标签云等)、文章推荐、收养狗狗、送养狗、留言等功能;

    后台主要功能模块包括:
    用户信息、流浪狗信息、疫苗管理、收养记录、客服管理等;

    环境需要

    1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。

    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
    5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 

    6.数据库:MySql 5.7版本;

    技术栈

    1. 后端:Spring SpringMVC MyBatis

    2. 前端:JSP+Bootstrap+JQuery

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

    2. 将项目中db.properties配置文件中的数据库配置改为自己的配置

    3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

    若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;

    4.修改DogController.java中第86行及第147行左右的uploadDB,根据自己的系统打开对应代码;

    5. 运行项目,输入localhost:8080/ssm-adopt 登录

    运行截图

    前台界面

     

     

     

     

     

     

    后台界面

     

     

     

     

    相关代码 

    AdoptController

    1. package com.ypf.controller;
    2. import org.springframework.beans.factory.annotation.Autowired;
    3. import org.springframework.stereotype.Controller;
    4. import org.springframework.web.bind.annotation.RequestMapping;
    5. import org.springframework.web.bind.annotation.ResponseBody;
    6. import com.ypf.pojo.TDogUser;
    7. import com.ypf.pojo.TUser;
    8. import com.ypf.service.AdoptService;
    9. import com.ypf.utils.AdoptJSONResult;
    10. import com.ypf.utils.JqGridResult;
    11. @Controller
    12. @RequestMapping("/adopt")
    13. public class AdoptController extends BaseController{
    14. @Autowired
    15. private AdoptService adoptService;
    16. @RequestMapping("/showAdoptRecordInfoListPage")
    17. public String showUserInfoListPage(){
    18. return "/record/adoptRecordInfoList";
    19. }
    20. @RequestMapping("/showAdoptUserInfoPage")
    21. public String showAdoptUserInfoPage(){
    22. return "/record/adoptUserInfoList";
    23. }
    24. @RequestMapping("/getAdoptRecordInfoList")
    25. @ResponseBody
    26. public JqGridResult getAdoptRecordInfoList(TUser user,Integer page){
    27. if(page == null){
    28. page = 1;
    29. }
    30. JqGridResult jqGridResult = adoptService.queryAllAdoptRecord(page,pageSize);
    31. return jqGridResult;
    32. }
    33. @RequestMapping("/getAdoptUserInfoList")
    34. @ResponseBody
    35. public JqGridResult getAdoptUserInfoList(TUser user,Integer page){
    36. if(page == null){
    37. page = 1;
    38. }
    39. JqGridResult jqGridResult = adoptService.queryAllAdoptUser(page, pageSize);
    40. return jqGridResult;
    41. }
    42. @RequestMapping("/delete")
    43. @ResponseBody
    44. public AdoptJSONResult deleteComment(Integer recordId){
    45. adoptService.deleteAdoptRecord(recordId);
    46. return AdoptJSONResult.ok();
    47. }
    48. @RequestMapping("/modifyAdoptRecord")
    49. @ResponseBody
    50. public AdoptJSONResult modifyAdoptRecord(TDogUser adoptRecord){
    51. //修改 status 0:未审核 1:审核通过
    52. adoptRecord.setStatus(1);
    53. adoptService.updateAdoptRecord(adoptRecord);
    54. return AdoptJSONResult.ok();
    55. }
    56. }

    BaseController

    1. package com.ypf.controller;
    2. import java.util.HashMap;
    3. import java.util.List;
    4. import java.util.Map;
    5. import javax.servlet.http.HttpServletRequest;
    6. import javax.servlet.http.HttpSession;
    7. import org.springframework.validation.BindingResult;
    8. import org.springframework.validation.FieldError;
    9. import com.ypf.pojo.TAdmin;
    10. /**
    11. * @Description: basic controller, controller中的大部分通用方法写在此
    12. */
    13. public class BaseController {
    14. /**
    15. * 默认分页行数
    16. */
    17. public static final Integer pageSize = 10;
    18. /**
    19. *
    20. * @Description: 验证并且获得获得bean上的错误
    21. * @param result
    22. * @return
    23. */
    24. protected Map getErrors(BindingResult result) {
    25. Map map = new HashMap();
    26. List list = result.getFieldErrors();
    27. for (FieldError error : list) {
    28. map.put(error.getField(), error.getDefaultMessage());
    29. }
    30. return map;
    31. }
    32. /**
    33. *
    34. * @Description: 获得域名地址路径
    35. * @param request
    36. * @return
    37. */
    38. protected String getWebUrlAddress(HttpServletRequest request) {
    39. StringBuffer url = request.getRequestURL();
    40. String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString();
    41. return tempContextUrl;
    42. }
    43. protected TAdmin getCurrentUser(HttpServletRequest request) {
    44. HttpSession session = request.getSession();
    45. TAdmin admin = (TAdmin) session.getAttribute("sessionAdmin");
    46. return admin;
    47. }
    48. }

    DogController

    1. package com.ypf.controller;
    2. import java.io.File;
    3. import java.io.FileOutputStream;
    4. import java.io.IOException;
    5. import java.io.InputStream;
    6. import java.io.OutputStream;
    7. import java.util.Date;
    8. import javax.servlet.http.HttpServletRequest;
    9. import javax.servlet.http.HttpSession;
    10. import org.apache.commons.io.IOUtils;
    11. import org.springframework.beans.factory.annotation.Autowired;
    12. import org.springframework.stereotype.Controller;
    13. import org.springframework.web.bind.annotation.PostMapping;
    14. import org.springframework.web.bind.annotation.RequestMapping;
    15. import org.springframework.web.bind.annotation.RequestParam;
    16. import org.springframework.web.bind.annotation.ResponseBody;
    17. import org.springframework.web.multipart.MultipartFile;
    18. import org.springframework.web.servlet.ModelAndView;
    19. import com.ypf.pojo.TDog;
    20. import com.ypf.pojo.TDogUser;
    21. import com.ypf.pojo.TUser;
    22. import com.ypf.service.AdoptService;
    23. import com.ypf.service.DogService;
    24. import com.ypf.utils.AdoptJSONResult;
    25. import com.ypf.utils.JqGridResult;
    26. @Controller
    27. @RequestMapping("/dog")
    28. public class DogController extends BaseController{
    29. @Autowired
    30. private DogService dogService;
    31. @Autowired
    32. private AdoptService adoptService;
    33. @RequestMapping("/showDogInfoListPage")
    34. public String showDogInfoListPage(){
    35. return "/dog/dogInfoList";
    36. }
    37. @RequestMapping("/showCreateDogPage")
    38. public ModelAndView showCreateDogPage(HttpServletRequest request){
    39. ModelAndView mv = new ModelAndView("dog/createDog");
    40. return mv;
    41. }
    42. @RequestMapping("/getDogInfoList")
    43. @ResponseBody
    44. public JqGridResult getDogInfoList(TDog dog,Integer page){
    45. if(page == null){
    46. page = 1;
    47. }
    48. JqGridResult jqGridResult = dogService.queryAllDog(dog, page, pageSize);
    49. return jqGridResult;
    50. }
    51. @RequestMapping("/delete")
    52. @ResponseBody
    53. public AdoptJSONResult deleteDog(Integer dogId){
    54. dogService.deleteDog(dogId);
    55. return AdoptJSONResult.ok();
    56. }
    57. @RequestMapping("/saveOrUpdate")
    58. @ResponseBody
    59. public AdoptJSONResult saveOrUpdate(TDog dog,@RequestParam(name="file",required=false) MultipartFile file,
    60. HttpServletRequest request) throws IOException{
    61. // 狗id不为空,则修改狗;狗id为空,则新建狗
    62. Integer dogId = dog.getId();
    63. if (dogId != null) {
    64. dogService.updateDog(dog);
    65. } else {
    66. if(file != null){
    67. //保存到数据库的路径
    68. String temp=Thread.currentThread().getContextClassLoader().getResource("").getPath();
    69. int num=temp.indexOf(".metadata");
    70. //String path=temp.substring(1,num).replace('/', '\\')+request.getContextPath().replaceAll("/", "")+"\\src\\main\\webapp\\";
    71. String path=request.getSession().getServletContext().getRealPath("");
    72. // windows下使用该路径;
    73. //String uploadDB = "static\\pages\\img\\dog\\";
    74. // mac下使用该路径
    75. String uploadDB = "static/pages/img/dog/";
    76. String fileName = file.getOriginalFilename();
    77. String[] fileNames = fileName.split("\\.");
    78. String sufixName = fileNames[fileNames.length-1];
    79. fileName = new Date().getTime() + "." +sufixName;
    80. uploadDB += fileName;
    81. dog.setFaceImage(uploadDB);
    82. InputStream in = file.getInputStream();
    83. File finalFile = new File(path+uploadDB);
    84. OutputStream os = new FileOutputStream(finalFile);
    85. IOUtils.copy(in, os);
    86. }
    87. dogService.addDog(dog);
    88. }
    89. return AdoptJSONResult.ok();
    90. }
    91. @RequestMapping("/saveAdoptUserInfo")
    92. public String saveOrUpdate(TDog dog,HttpServletRequest request) throws IOException{
    93. HttpSession session = request.getSession();
    94. dogService.addDog(dog);
    95. int dogId = dog.getId();
    96. TDogUser adopt = new TDogUser();
    97. TUser user = (TUser) session.getAttribute("sessionUser");
    98. adopt.setUserId(user.getId());
    99. //type 1:收养 2:送养
    100. adopt.setType(2);
    101. adopt.setStatus(0);
    102. adopt.setDogId(dogId);
    103. adoptService.addAdoptRecord(adopt);
    104. return "forward:/frontPage/adoptDog.jsp";
    105. }
    106. @RequestMapping("/showModifyDogPage")
    107. public ModelAndView showModifyDog(Integer dogId, HttpServletRequest request){
    108. // 查询狗信息
    109. TDog dogInfo = dogService.queryDogInfoById(dogId);
    110. ModelAndView mv = new ModelAndView("dog/modifyDog");
    111. mv.addObject("dogInfo", dogInfo);
    112. return mv;
    113. }
    114. @PostMapping("/upload")
    115. @ResponseBody
    116. public AdoptJSONResult faceUpload(MultipartFile file,HttpServletRequest request)throws Exception{
    117. //保存到数据库中的相对路径
    118. // windows系统
    119. String uploadPathDB = "static\\pages\\img\\dog\\";
    120. try {
    121. if(file != null){
    122. //保存到数据库的路径
    123. String temp=Thread.currentThread().getContextClassLoader().getResource("").getPath();
    124. int num=temp.indexOf(".metadata");
    125. //String path=temp.substring(1,num).replace('/', '\\')+request.getContextPath().replaceAll("/", "")+"\\src\\main\\webapp\\";
    126. String path=request.getSession().getServletContext().getRealPath("");
    127. // mac系统
    128. //uploadPathDB = "static/pages/img/dog/";
    129. String fileName = file.getOriginalFilename();
    130. String[] fileNames = fileName.split("\\.");
    131. String sufixName = fileNames[fileNames.length-1];
    132. fileName = new Date().getTime() + "." +sufixName;
    133. uploadPathDB += fileName;
    134. InputStream in = file.getInputStream();
    135. File finalFile = new File(path+uploadPathDB);
    136. OutputStream os = new FileOutputStream(finalFile);
    137. IOUtils.copy(in, os);
    138. }else{
    139. return AdoptJSONResult.errorMsg("上传出错...");
    140. }
    141. } catch (Exception e) {
    142. e.printStackTrace();
    143. return AdoptJSONResult.errorMsg("上传出错...");
    144. }
    145. return AdoptJSONResult.ok(uploadPathDB);
    146. }
    147. }

    疫苗管理Controller

    1. package com.ypf.controller;
    2. import java.util.List;
    3. import javax.servlet.http.HttpServletRequest;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.ResponseBody;
    8. import org.springframework.web.servlet.ModelAndView;
    9. import com.ypf.pojo.TDog;
    10. import com.ypf.pojo.TDogVaccine;
    11. import com.ypf.pojo.TVaccine;
    12. import com.ypf.service.DogService;
    13. import com.ypf.service.VaccineService;
    14. import com.ypf.utils.AdoptJSONResult;
    15. import com.ypf.utils.JqGridResult;
    16. /**
    17. * 疫苗管理Controller
    18. * @author 11023
    19. *
    20. */
    21. @Controller
    22. @RequestMapping("/vaccine")
    23. public class VaccineController extends BaseController{
    24. @Autowired
    25. private VaccineService vaccineService;
    26. @Autowired
    27. private DogService dogService;
    28. @RequestMapping("/showVaccineInfoListPage")
    29. public String showVaccineInfoListPage(){
    30. return "/vaccine/vaccineInfoList";
    31. }
    32. @RequestMapping("/showDogVaccineInfoListPage")
    33. public String showDogVaccineInfoListPage(){
    34. return "/vaccine/dogVaccineInfoList";
    35. }
    36. @RequestMapping("/showCreateVaccinePage")
    37. public ModelAndView showCreateVaccinePage(HttpServletRequest request){
    38. ModelAndView mv = new ModelAndView("vaccine/createVaccine");
    39. return mv;
    40. }
    41. @RequestMapping("/delete")
    42. @ResponseBody
    43. public AdoptJSONResult deleteVaccine(Integer vaccineId){
    44. vaccineService.deleteVaccine(vaccineId);
    45. return AdoptJSONResult.ok();
    46. }
    47. @RequestMapping("/getVaccineInfoList")
    48. @ResponseBody
    49. public JqGridResult getVaccineInfoList(TVaccine vaccine,Integer page){
    50. if(page == null){
    51. page = 1;
    52. }
    53. JqGridResult jqGridResult = vaccineService.queryAllVaccine(vaccine, page, pageSize);
    54. return jqGridResult;
    55. }
    56. @RequestMapping("/getDogVaccineInfoList")
    57. @ResponseBody
    58. public JqGridResult getDogVaccineInfoList(TDogVaccine dogVaccine,Integer page){
    59. if(page == null){
    60. page = 1;
    61. }
    62. JqGridResult jqGridResult = vaccineService.queryDogVaccine(dogVaccine, page, pageSize);
    63. return jqGridResult;
    64. }
    65. @RequestMapping("/saveOrUpdate")
    66. @ResponseBody
    67. public AdoptJSONResult saveOrUpdate(TVaccine vaccine){
    68. Integer vaccineId = vaccine.getId();
    69. if (vaccineId != null) {
    70. vaccineService.updateVaccine(vaccine);
    71. } else {
    72. vaccineService.addVaccine(vaccine);
    73. }
    74. return AdoptJSONResult.ok();
    75. }
    76. @RequestMapping("/modifyVaccine")
    77. public ModelAndView showModifyUser(Integer vaccineId, HttpServletRequest request){
    78. // 查询疫苗信息
    79. TVaccine vaccineInfo = vaccineService.queryVaccineInfoById(vaccineId);
    80. ModelAndView mv = new ModelAndView("vaccine/modifyVaccine");
    81. mv.addObject("vaccineInfo", vaccineInfo);
    82. return mv;
    83. }
    84. @RequestMapping("/modifyDogVaccine")
    85. public ModelAndView modifyDogVaccine(Integer dogId, HttpServletRequest request){
    86. // 查询流浪狗接种疫苗信息
    87. TDog dogInfo = dogService.queryDogInfoById(dogId);
    88. ModelAndView mv = new ModelAndView("vaccine/modifyDogVaccine");
    89. mv.addObject("dogInfo", dogInfo);
    90. //查询疫苗信息
    91. JqGridResult jqGridResult = vaccineService.queryAllVaccine(null, 1, pageSize);
    92. List vaccineInfoList = (List) jqGridResult.getRows();
    93. mv.addObject("vaccineInfoList", vaccineInfoList);
    94. return mv;
    95. }
    96. /**
    97. * 保存接种疫苗记录
    98. * @param dogVaccine
    99. * @return
    100. */
    101. @RequestMapping("/saveDogVaccine")
    102. @ResponseBody
    103. public AdoptJSONResult saveDogVaccine(TDogVaccine dogVaccine){
    104. //改变是否接种疫苗状态
    105. Integer dogId = dogVaccine.getDogId();
    106. TDog dog = dogService.queryDogInfoById(dogId);
    107. dog.setVaccinationStatus(2);
    108. dogService.updateDog(dog);
    109. //接种疫苗 相应的疫苗库存 -1
    110. Integer vaccineId = dogVaccine.getVaccineId();
    111. TVaccine vaccine = vaccineService.queryVaccineInfoById(vaccineId);
    112. vaccine.setVaccineCount(vaccine.getVaccineCount()-1);
    113. vaccineService.updateVaccine(vaccine);
    114. //添加接种记录
    115. vaccineService.addDogVaccine(dogVaccine);
    116. return AdoptJSONResult.ok();
    117. }
    118. }

    如果也想学习本系统,下面领取。关注并回复:031ssm

  • 相关阅读:
    OpenCV-Python学习(3)—— OpenCV 图像色彩空间转换
    【Mining Data】收集数据(使用 Python 挖掘 Twitter 数据)
    Innodb底层原理与Mysql日志机制
    2022最新版-李宏毅机器学习深度学习课程-P22 卷积神经网络CNN
    优化您的部署:Docker 镜像最佳实践
    云原生Kubernetes之浅认知
    羧甲基-β-环糊精/Fe3O4纳米复合物|聚苯胺/TiO2-Fe3O4二元纳米复合物|PAn/TiO2/Fe3O4聚苯胺(PAn)微米纤维材料
    C++中的无限循环
    在R中通过正则化表达式提取向量中的正负数
    python-arima模型statsmodels库实现-有数据集(续)-statsmodels-0.9.0版本
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126788927