【734】基于springboot流浪宠物救助领养管理系统源码和论文
21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们所认识,科学化的管理,使信息存储达到准确、快速、完善,并能提高工作管理效率,促进其发展。
本流浪动物救助及领养管理系统以Springboot作为框架,前端bootstrap技术,B/S模式以及MySql作为后台运行的数据库。本系统主要包括以下功能模块:用户管理,动物类别管理,帖子管理,动物管理管理,动物列表,公告管理,动物领养管理,动物捐赠管理,评论管理,个人信息,通过这些模块的实现能够基本满足日常流浪动物救助及领养管理系统的操作。本文着重阐述了流浪动物救助及领养管理系统的分析、设计与实现,首先介绍开发系统和环境配置、数据库的设计,接着说明功能模块的详细实现,最后进行了总结。
关键词:流浪动物救助平台; SpringBoot框架;MySql;bootstrap
ABSTRACT
Today in the 21st century, with the continuous development and progress of society, people's understanding of information science has developed from a low level to a high level, from the original perceptual knowledge to rational knowledge. The importance of management has gradually been recognized by people. Scientific management makes information storage accurate, fast and perfect, and can improve the efficiency of work management and promote its development.
This stray animal rescue and adoption management system uses Springboot as the framework, and the front-end bootstrap technology, B/S mode and MySql as the database running in the background. The system mainly includes the following functional modules: user management, animal category management, post management, animal management management, animal list, announcement management, animal adoption management, animal donation management, comment management, personal information. The implementation of these modules can basically meet the operation of the daily stray animal rescue and adoption management system. This paper focuses on the analysis, design and implementation of the stray animal rescue and adoption management system. First, it introduces the development system, environmental configuration, and database design. Then it describes the detailed implementation of the functional modules. Finally, it summarizes.
Keywords: stray animal rescue platform; SpringBoot framework; MySql; Bootstrap technology
package com.rescue.controller;
import com.github.pagehelper.PageInfo;
import com.rescue.entity.*;
import com.rescue.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class IndexController {
@Autowired
AnimalService animalService;
@Autowired
CategoryService categoryService;
@Autowired
BoardService boardService;
@Autowired
CommentsService commentsService;
@Autowired
UserService userService;
@Autowired
DonateService donateService;
@Autowired
NotifyService notifyService;
@Autowired
SqlyService sqlyService;
//主页面
@RequestMapping("/toIndex")
public String toIndex(Model model, Animal animal,
@RequestParam(required = false,defaultValue = "1") Integer pageNum,
@RequestParam(required = false,defaultValue = "8") Integer pageSize,
HttpSession httpSession, HttpServletRequest request){
if (animal.getName() != null){
request.setAttribute("name",animal.getName());
}
httpSession.setAttribute("pageNum",pageNum);
httpSession.setAttribute("pageSize",pageSize);
PageInfo<Animal> pageInfo = animalService.findAnimal(animal,pageNum,pageSize);
if (!(pageInfo.getSize() > 0)){
model.addAttribute("status","暂无记录");
}
model.addAttribute("pageInfo",pageInfo);
model.addAttribute("url","toIndex");
List<Category> categoryList = categoryService.selectAll();
model.addAttribute("categoryList",categoryList);
return "index/index";
}
//主页面
@RequestMapping("/toAnimalIndex")
public String toAnimalIndex(Model model, Animal animal,
@RequestParam(required = false,defaultValue = "1") Integer pageNum,
@RequestParam(required = false,defaultValue = "8") Integer pageSize,
HttpSession httpSession, HttpServletRequest request){
if (animal.getName() != null){
request.setAttribute("name",animal.getName());
}
httpSession.setAttribute("pageNum",pageNum);
httpSession.setAttribute("pageSize",pageSize);
PageInfo<Animal> pageInfo = animalService.findAnimal(animal,pageNum,pageSize);
if (!(pageInfo.getSize() > 0)){
model.addAttribute("status","暂无记录");
}
model.addAttribute("pageInfo",pageInfo);
model.addAttribute("url","toAnimalIndex");
List<Category> categoryList = categoryService.selectAll();
model.addAttribute("categoryList",categoryList);
List<Notify> notifyList = notifyService.selectAll(new HashMap());
model.addAttribute("notifyList",notifyList);
return "index/animal_index";
}
//帖子
@RequestMapping("/toBoard")
public String toBoard(Model model, Board Board,
@RequestParam(required = false,defaultValue = "1") Integer pageNum,
@RequestParam(required = false,defaultValue = "8") Integer pageSize,
HttpSession httpSession, HttpServletRequest request){
if (Board.getTitle() != null){
request.setAttribute("name",Board.getTitle());
}
httpSession.setAttribute("pageNum",pageNum);
httpSession.setAttribute("pageSize",pageSize);
PageInfo<Board> pageInfo = boardService.findBoard(Board,pageNum,pageSize);
if (!(pageInfo.getSize() > 0)){
model.addAttribute("status","暂无记录");
}
model.addAttribute("pageInfo",pageInfo);
model.addAttribute("url","toBoard");
List<Category> categoryList = categoryService.selectAll();
model.addAttribute("categoryList",categoryList);
List<Notify> notifyList = notifyService.selectAll(new HashMap());
model.addAttribute("notifyList",notifyList);
return "index/board";
}
/**
* 发表帖子
* @return
*/
@RequestMapping("/toIndexBoard")
public String toIndexBoard(){
return "index/add";
}
/**
* 发表帖子
* @return
*/
@RequestMapping("/toRegister")
public String toRegister(){
return "index/register";
}
/**
* 修改帖子
* @return
*/
@RequestMapping("/toIndexUpdateBoard")
public String toIndexUpdateBoard(Integer id,Model model){
Board board = boardService.getBoardById(id);
model.addAttribute("board",board);
return "index/update";
}
/**
* 动物详情
* @param model
* @param aid
* @param httpSession
* @param request
* @return
*/
@RequestMapping("/toAnimalDetail")
public String toAnimalDetail(Model model, Integer aid,HttpSession httpSession, HttpServletRequest request){
Animal animal = animalService.getAnimalById(aid);
animal.setCategory(categoryService.getCategoryById(animal.getC_id()));
model.addAttribute("animal",animal);
Map map = new HashMap<>();
map.put("aid",aid);
// List<Comments> commentsList = commentsService.selectAll(map);
// model.addAttribute("commentsList",commentsList);
return "index/animal_detail";
}
/**
* 帖子详情
* @param model
* @param bid
* @param httpSession
* @param request
* @return
*/
@RequestMapping("/toBoardDetail")
public String toBoardDetail(Model model, Integer bid,HttpSession httpSession, HttpServletRequest request){
Board board = boardService.getBoardById(bid);
model.addAttribute("board",board);
Map map = new HashMap<>();
map.put("bid",bid);
List<Comments> commentsList = commentsService.selectAll(map);
model.addAttribute("commentsList",commentsList);
return "index/board_detail";
}
/**
* 我的帖子
* @param model
* @param bid
* @param request
* @return
*/
@RequestMapping("/toUserIndex")
public String toUserIndex(Model model, Integer bid, HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
Map map = new HashMap<>();
map.put("uid",user!=null?user.getId():null);
List<Board> boardList = boardService.selectAll(map);
model.addAttribute("boardList",boardList);
model.addAttribute("counts",boardList.size());
return "index/user_index";
}
/**
* 我的评论
* @param model
* @param bid
* @param request
* @return
*/
@RequestMapping("/toUserComments")
public String toUserComments(Model model, Integer bid, HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
Map map = new HashMap<>();
map.put("uid",user!=null?user.getId():null);
List<Comments> commentsList = commentsService.selectAll(map);
model.addAttribute("commentsList",commentsList);
model.addAttribute("counts",commentsList.size());
return "index/user_com";
}
/**
* 个人信息
* @param model
* @param request
* @return
*/
@RequestMapping("/toMyInfo")
public String toMyInfo(Model model, HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
User data = userService.getUserById(user.getId());
model.addAttribute("data",data);
return "index/set";
}
/**
* 我的申请
* @param model
* @param request
* @return
*/
@RequestMapping("/myApply")
public String myApply(Model model, HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
Map map = new HashMap<>();
map.put("uid",user!=null?user.getId():null);
List<Sqly> sqlyList = sqlyService.selectAll(map);
for(Sqly sqly :sqlyList){
sqly.setUser(userService.getUserById(sqly.getUid()));
sqly.setAnimal(animalService.getAnimalById(sqly.getAid()));
}
model.addAttribute("sqlyList",sqlyList);
return "index/user_sqly";
}
/**
* 爱心捐赠
* @param model
* @param request
* @return
*/
@RequestMapping("/toAnimalDonate")
public String toAnimalDonate(Model model,Integer aid, HttpServletRequest request){
model.addAttribute("aid",aid);
return "index/addDonate";
}
/**
* 申请领养
* @param model
* @param request
* @return
*/
@RequestMapping("/toAnimalSqly")
public String toAnimalSqly(Model model,Integer aid, HttpServletRequest request){
model.addAttribute("aid",aid);
return "index/sqly";
}
}
package com.rescue.controller;
import com.rescue.entity.Admin;
import com.rescue.entity.User;
import com.rescue.service.LoginService;
import org.apache.catalina.Store;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.sql.Driver;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Controller
public class LoginController {
@Autowired
private LoginService loginService;
/**
* 登录
* @param username
* @param password
* @param type
* @param httpSession
* @param model
* @return
* @throws UnsupportedEncodingException
*/
@RequestMapping(value = "/loginUser",method = RequestMethod.POST)
public String loginUser( String username,String password, String type,HttpSession httpSession, Model model) throws UnsupportedEncodingException {
Admin admin = new Admin();
if(type !=null&& type.equals("1")){
admin = loginService.selectAdmin(username,password);
if (admin != null){
httpSession.setAttribute("username",admin.getUsername());
httpSession.setAttribute("admin",admin);
httpSession.setAttribute("type",type);
model.addAttribute("type",type);
return "home/homepage";
}else{
model.addAttribute("status","账号或者密码输入错误!");
return "login";
}
}
else if(type.equals("2")){//用户
User user = loginService.selectUser(username,password);
if(user != null){
httpSession.setAttribute("username",user.getRealname());
httpSession.setAttribute("user",user);
httpSession.setAttribute("type",type);
model.addAttribute("type",type);
return "redirect:/toIndex";
//return "home/homepage";
}else{
model.addAttribute("status","账号或者密码输入错误!");
return "login";
}
}else{
model.addAttribute("status","账号或者密码输入错误!");
return "login";
}
}
/* @RequestMapping(value = "/registerUser",method = RequestMethod.POST)
public ModelAndView addLeader(User user, String code, HttpSession httpSession){
ModelAndView modelAndView = new ModelAndView();
User users = loginService.selectUserByUserName(user.getUsername());
if(users == null){
loginService.addUser(user);
modelAndView.addObject("status","注册成功");
modelAndView.setViewName("login");
}else{
modelAndView.addObject("status","用户名重复!");
modelAndView.setViewName("register");
}
return modelAndView;
}*/
/**
* 登出
* @param httpSession
* @return
*/
@RequestMapping(value = "/outLogin",method = RequestMethod.GET)
public String outLogin(HttpSession httpSession){
httpSession.invalidate();
return "login";
}
@RequestMapping(value = "/toConsole")
public String toConsole() {
return "console";
}
@RequestMapping(value = "/toMap")
public String toMap( ) {
return "map/baidu";
}
@RequestMapping(value = "/toMapAdmin")
public String toMapAdmin( ) {
return "map/baiduAdmin";
}
@RequestMapping(value = "/echart")
public String echart( ) {
return "son/echart";
}
@RequestMapping(value = "/toUpdateAdmin")
public String toUpdateAdmin( ) {
return "admin/admin";
}
//修改管理员
@RequestMapping("/updateAdmin")
@ResponseBody
public String updateAdmin(String newPass,String password, Model model, HttpSession httpSession){
Admin aa = (Admin)(httpSession.getAttribute("admin"));
String message = "no";
if(aa!=null && aa.getPassword().equals(password)){
aa.setPassword(newPass);
loginService.updateAdmin(aa);
message = "yes";
}
return message;
}
@ResponseBody
@RequestMapping("/upload")
public Map upload(MultipartFile file, HttpServletRequest request){
String prefix="";
String dateStr="";
OutputStream out = null;
InputStream fileInput=null;
try{
if(file!=null){
String originalName = file.getOriginalFilename();
prefix=originalName.substring(originalName.lastIndexOf(".")+1);
Date date = new Date();
String uuid = UUID.randomUUID()+"";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateStr = simpleDateFormat.format(date);
String filepath = "D:\\upload\\" + dateStr+"\\"+uuid+"." + prefix;
File files=new File(filepath);
System.out.println(filepath);
if(!files.getParentFile().exists()){
files.getParentFile().mkdirs();
}
file.transferTo(files);
Map<String,Object> map2=new HashMap<>();
Map<String,Object> map=new HashMap<>();
map.put("code",0);
map.put("msg","");
map.put("data",map2);
map2.put("src","/images/"+dateStr+"/"+uuid+"." + prefix);
return map;
}
}catch (Exception e){
}finally{
try {
if(out!=null){
out.close();
}
if(fileInput!=null){
fileInput.close();
}
} catch (Exception e) {
}
}
Map<String,Object> map=new HashMap<>();
map.put("code",1);
map.put("msg","");
return map;
}
}