该项目使用spring mvc,spring,mybatis框架组合。分为前端和后端两部分,主要功能包括:领养中心,团队活动,领养管理,流浪猫狗管理,志愿者申请,领养列表等。适合喜爱动物的同学,目前流浪猫狗很多,同学可以通过该网站发布需要救助的流浪猫狗信息,便于有爱心的人士收养。
jdk8+tomcat8+mysql+maven+IntelliJ IDEA(或Eclipse)
spring+spring mvc+mybatis+layui+jquery+jsp
首页
领养中心团队展示
用户信息管理
流浪猫狗信息管理
评价管理
志愿者申请
管理员controller 控制层
/**
*/
@Controller
@RequestMapping("admin")
public class AdminController {
@Autowired
private AdminService adminService;
@RequestMapping("admins.action")
@ResponseBody
public Message getAdmins(@RequestParam(value = "pn",defaultValue = "1") Integer pn){
// 引入PageHelper分页插件
// 在查询之前只需要调用,传入页码,以及每页的大小
PageHelper.startPage(pn,4);
List<Admin> admins = adminService.getAdmins();
// startPage后面紧跟的这个查询就是一个分页查询
System.out.println(admins+"admins");
// 使用pageInfo包装查询后的结果,只需要将pageInfo交给页面就行了。
// 封装了详细的分页信息,包括有我们查询出来的数据,传入连续显示的页数
PageInfo page=new PageInfo(admins,2);
return Message.success().add("pageInfo",page);
}
@RequestMapping("create.action")
@ResponseBody
public Message addAdmin(Admin admin){
int i = adminService.addAdmin(admin);
System.out.println(i);
if(i>0){
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("delete.action")
@ResponseBody
public Message deleteAdmin(Integer id){
int i = adminService.deleteAdmin(id);
if(i>0){
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("update.action")
@ResponseBody
public Message updateAdmin(Admin admin,MultipartFile file){
System.out.println(111);
if(file!=null && file.equals("")==false) {
String load = FileLoad.load(file);
admin.setPic(load);
}
int i = adminService.updateAdmin(admin);
System.out.println(i);
if(i>0){
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("findById.action")
@ResponseBody
public Message findById(Integer id) throws ParseException {
Admin admin = adminService.findById(id);
if(admin!=null){
return Message.success().add("admin",admin);
}else{
return Message.fail();
}
}
@RequestMapping("/findByName.action")
@ResponseBody
public Message findByName(@RequestParam(value = "pn",defaultValue = "1") Integer pn,String adminName){
PageHelper.startPage(pn,4);
List<Admin> admins = adminService.findByName(adminName);
if(admins!=null){
PageInfo page = new PageInfo(admins,2);
return Message.success().add("pageInfo",page);
}else{
return Message.fail();
}
}
@RequestMapping("logout.action")
public String logout(){
return "admin/login";
}
}
动物Controller控制层
*/
@Controller
@RequestMapping("answer")
public class AnswerController {
@Autowired
private AnswerService answerService;
@Autowired
private CommentService commentService;
@RequestMapping("create.action")
@ResponseBody
public Message addAnswer(Integer ids,String content, HttpServletRequest request){
Answer answer=new Answer();
Users user = (Users)request.getSession().getAttribute("user");
answer.setComment(commentService.findById(ids));
answer.setAnswerTime(new Date());
answer.setUser(user);
answer.setContent(content);
int i = answerService.addAnswer(answer);
if(i>0){
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("creates.action")
@ResponseBody
public Message addAnswers(Integer id,String content,Integer comment_id,HttpServletRequest request){
Answer answer=new Answer();
Users user = (Users)request.getSession().getAttribute("user");
answer.setComment(commentService.findById(comment_id));
answer.setAnswer(answerService.findById(id));
answer.setAnswerTime(new Date());
answer.setUser(user);
answer.setContent(content);
int i = answerService.addAnswers(answer);
if(i>0){
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("findByCommentId.action")
@ResponseBody
public Message findByCommentId(Integer comment_id){
List<Answer> answers = answerService.findByCommentId(comment_id);
System.out.println(answers);
if(answers!=null){
return Message.success().add("answer",answers);
}else{
return Message.fail();
}
}
@RequestMapping("findById.action")
@ResponseBody
public Message findById(Integer id){
Answer answer = answerService.findById(id);
System.out.println(answer);
if(answer!=null){
return Message.success().add("answer",answer);
}else{
return Message.fail();
}
}
}
用户Controller 代码
/**
*/
@Controller
@RequestMapping("user")
public class UsersController {
@Autowired
private UsersService usersService;
@RequestMapping("users.action")
@ResponseBody
public Message getUsers(@RequestParam(value = "pn",defaultValue = "1") Integer pn){
PageHelper.startPage(pn,4);
List<Users> users = usersService.getUsers();
System.out.println(users);
PageInfo page=new PageInfo(users,2);
return Message.success().add("pageInfo",page);
}
@RequestMapping("create.action")
@ResponseBody
public Message create(Users users){
if(usersService.addUser(users)>0){
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("delete.action")
@ResponseBody
public Message deleteUsers(Integer id){
if(usersService.deleteUser(id)>0){
return Message.fail();
}else{
return Message.fail();
}
}
@RequestMapping("update.action")
@ResponseBody
public Message updateUser(Users users,HttpServletRequest request){
if(usersService.updateUser(users)>0){
Users user=usersService.findById(users.getId());
request.getSession().setAttribute("user",user);
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("updatePic.action")
@ResponseBody
public Message updatePic(MultipartFile file,HttpServletRequest request){
Users user=(Users) request.getSession().getAttribute("user");
if(file!=null){
String load = FileLoad.load(file);
user.setPic(load);
}
if(usersService.updateUser(user)>0){
Users users = usersService.findById(user.getId());
request.getSession().setAttribute("user",users);
return Message.success();
}else{
return Message.fail();
}
}
@RequestMapping("findById.action")
@ResponseBody
public Message findById(Integer id){
Users user = usersService.findById(id);
if(user!=null){
return Message.success().add("user",user);
}else{
return Message.fail();
}
}
@RequestMapping("findByName.action")
@ResponseBody
public Message findByName(String userName,@RequestParam(value = "pn",defaultValue = "1") Integer pn){
PageHelper.startPage(pn,4);
List<Users> users = usersService.findByName(userName);
if(users!=null){
PageInfo page=new PageInfo(users,3);
return Message.success().add("pageInfo",page);
}else{
return Message.fail();
}
}
@RequestMapping("login.action")
@ResponseBody
public Message login(Users users, HttpServletRequest request){
Users user = usersService.loginUser(users);
if(user!=null){
request.getSession().setAttribute("user",user);
return Message.success().add("user",user);
}else{
return Message.fail();
}
}
@RequestMapping("logout.action")
@ResponseBody
public Message logout(HttpServletRequest request){
request.getSession().invalidate();
return Message.success();
}
}