From 63eabab51811507cc9843786f66538a460854221 Mon Sep 17 00:00:00 2001 From: px2r39hn8 <13419358548@163.com> Date: Fri, 28 Jun 2024 15:06:55 +0800 Subject: [PATCH] Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户登录注册、管理员登录注册、回复评论 --- README.md | 2 + admins.sql | 42 ++++++++ answer.sql | 52 ++++++++++ controller/AdminController.java | 152 ++++++++++++++++++++++++++++ controller/AnswerController.java | 52 ++++++++++ controller/UserController.java | 140 +++++++++++++++++++++++++ dao/AdminMapper.java | 8 ++ dao/AnswerMapper.java | 8 ++ dao/UserMapper.java | 7 ++ pojo/Admins.java | 26 +++++ pojo/Answer.java | 28 +++++ pojo/User.java | 27 +++++ service/AdminService.java | 19 ++++ service/AnswerService.java | 12 +++ service/UserService.java | 23 +++++ service/impl/AdminServiceImpl.java | 66 ++++++++++++ service/impl/AnswerServiceImpl.java | 85 ++++++++++++++++ service/impl/UserServiceImpl.java | 92 +++++++++++++++++ user.sql | 52 ++++++++++ util/Message.java | 68 +++++++++++++ 20 files changed, 961 insertions(+) create mode 100644 README.md create mode 100644 admins.sql create mode 100644 answer.sql create mode 100644 controller/AdminController.java create mode 100644 controller/AnswerController.java create mode 100644 controller/UserController.java create mode 100644 dao/AdminMapper.java create mode 100644 dao/AnswerMapper.java create mode 100644 dao/UserMapper.java create mode 100644 pojo/Admins.java create mode 100644 pojo/Answer.java create mode 100644 pojo/User.java create mode 100644 service/AdminService.java create mode 100644 service/AnswerService.java create mode 100644 service/UserService.java create mode 100644 service/impl/AdminServiceImpl.java create mode 100644 service/impl/AnswerServiceImpl.java create mode 100644 service/impl/UserServiceImpl.java create mode 100644 user.sql create mode 100644 util/Message.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..e8134ae --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# test1 + diff --git a/admins.sql b/admins.sql new file mode 100644 index 0000000..6e93f71 --- /dev/null +++ b/admins.sql @@ -0,0 +1,42 @@ +/* +Navicat MySQL Data Transfer + +Source Server : he +Source Server Version : 50636 +Source Host : localhost:3306 +Source Database : hlb + +Target Server Type : MYSQL +Target Server Version : 50636 +File Encoding : 65001 + +Date: 2024-06-28 13:12:37 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for admins +-- ---------------------------- +DROP TABLE IF EXISTS `admins`; +CREATE TABLE `admins` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `adminName` varchar(20) NOT NULL COMMENT '管理员的名字', + `adminPwd` varchar(20) NOT NULL COMMENT '密码', + `realName` varchar(20) NOT NULL COMMENT '真实的名字', + `telephone` varchar(20) NOT NULL COMMENT '电话', + `Email` varchar(20) NOT NULL, + `birthday` date NOT NULL, + `sex` varchar(3) NOT NULL, + `pic` varchar(100) DEFAULT 'a.png', + `remark` varchar(255) NOT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Records of admins +-- ---------------------------- +INSERT INTO `admins` VALUES ('1', 'tzp', '11', '123', '15797959509', '15281210084', '2000-12-11', '男', 'a1.png', 'asd'); +INSERT INTO `admins` VALUES ('2', 'xm', '11', '111', '12345678999', '15893336489', '2023-12-13', '女', 'a.png', 'dasdasd'); +INSERT INTO `admins` VALUES ('3', 'bc', '11', '122', '12345678766', '1234567876@qq.com', '2023-12-12', '女', 'a2.png', 'adsasd'); +INSERT INTO `admins` VALUES ('4', 'cc', '11', '122', '12345678766', '1234567876@qq.com', '2023-12-12', '女', 'a3.png', 'dasdasd'); diff --git a/answer.sql b/answer.sql new file mode 100644 index 0000000..1b4e338 --- /dev/null +++ b/answer.sql @@ -0,0 +1,52 @@ +/* +Navicat MySQL Data Transfer + +Source Server : he +Source Server Version : 50636 +Source Host : localhost:3306 +Source Database : hlb + +Target Server Type : MYSQL +Target Server Version : 50636 +File Encoding : 65001 + +Date: 2024-06-28 13:13:09 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for answer +-- ---------------------------- +DROP TABLE IF EXISTS `answer`; +CREATE TABLE `answer` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `userId` int(11) DEFAULT NULL, + `replayId` int(11) DEFAULT NULL, + `commentId` int(11) NOT NULL, + `answerTime` date NOT NULL, + `content` varchar(255) NOT NULL, + PRIMARY KEY (`id`) USING BTREE, + KEY `fk8` (`userId`) USING BTREE, + KEY `fk11` (`commentId`) USING BTREE, + KEY `fk10` (`replayId`) USING BTREE, + CONSTRAINT `fk10` FOREIGN KEY (`replayId`) REFERENCES `answer` (`id`), + CONSTRAINT `fk11` FOREIGN KEY (`commentId`) REFERENCES `comment` (`id`), + CONSTRAINT `fk8` FOREIGN KEY (`userId`) REFERENCES `user` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Records of answer +-- ---------------------------- +INSERT INTO `answer` VALUES ('1', '2', null, '8', '2018-08-23', '真乖'); +INSERT INTO `answer` VALUES ('2', '5', '1', '8', '2018-08-23', '好漂亮'); +INSERT INTO `answer` VALUES ('3', '3', '2', '8', '2019-09-06', '我也喜欢。'); +INSERT INTO `answer` VALUES ('5', '1', null, '8', '2019-09-07', '太爱了。'); +INSERT INTO `answer` VALUES ('6', '1', null, '8', '2019-09-07', '我也喜欢。'); +INSERT INTO `answer` VALUES ('7', '1', null, '11', '2019-09-07', '我也喜欢。'); +INSERT INTO `answer` VALUES ('8', '17', null, '8', '2019-09-08', '我也喜欢。'); +INSERT INTO `answer` VALUES ('9', '17', null, '8', '2019-09-08', '好漂亮'); +INSERT INTO `answer` VALUES ('10', '17', null, '12', '2019-09-09', '我也喜欢。'); +INSERT INTO `answer` VALUES ('11', '17', null, '11', '2019-09-09', '我也喜欢。'); +INSERT INTO `answer` VALUES ('12', '1', null, '3', '2024-06-26', '453311'); +INSERT INTO `answer` VALUES ('13', '1', null, '3', '2024-06-26', '基地啊司机的驾驶的集结地阿三基地啊家是基督教按时间嗲是基地啊家是低价啊是第几点击洒几滴静安寺嗲是基地啊是近代世界的i大家说大家时间嗲是基地啊家上帝哦哦就基地啊是基地啊家上帝啊世界第几啊是哦对基地啊世界第哦啊降低哦骄傲地哦交大急啊多久啊是大家基地啊家低价圣诞节哦i阿娇级大神单价单价较低哦奥军第九的教师基地啊家嗲基地啊实际上都i静安寺军第哦啊世界第哦啊降低哦哦阿姐、基地啊司机的驾驶的集结地阿三基地啊家是基督教按时间嗲是基地啊家是基地啊司机的驾驶的集结地阿三基地啊家是基督教按时间嗲是基地啊家是'); diff --git a/controller/AdminController.java b/controller/AdminController.java new file mode 100644 index 0000000..5d63fe7 --- /dev/null +++ b/controller/AdminController.java @@ -0,0 +1,152 @@ +package club.controller; + +import club.pojo.Admins; +import club.service.AdminService; +import club.service.UserService; +import club.util.Message; +import com.github.pagehelper.PageInfo; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpSession; +@Controller +@RequestMapping("/admin") +public class AdminController { + @Resource + private AdminService adminService; + + @RequestMapping("/create") + @ResponseBody + public Message add(Admins admins, MultipartFile file){ + String pic = FileLoad.uploadAdminPic(file); + admins.setPic(pic); + int add = adminService.add(admins); + if(add>0){ + return Message.success(); + }else{ + return Message.fail(); + } + } + + @RequestMapping("findById") + @ResponseBody + public Message findById(Integer id){ + Admins byId = adminService.findById(id); + return Message.success().add("admin",byId); + } + + @RequestMapping("/update") + @ResponseBody + public Message update(Admins admins, MultipartFile file){ + if (file != null && file.getSize() > 0){ + String pic = FileLoad.uploadAdminPic(file); + admins.setPic(pic); + } + int update = adminService.update(admins); + if(update>0){ + return Message.success(); + }else { + return Message.fail(); + } + } + + @RequestMapping("/delete") + @ResponseBody + public Message del(Integer id){ + int del = adminService.del(id); + if(del>0){ + return Message.success(); + }else { + return Message.fail(); + } + } + + @RequestMapping("/admins") + @ResponseBody + public Message admins(@RequestParam(required = false) String adminName,@RequestParam("pn") Integer pageNum){ + Integer pageSize = 4; + if(pageNum == null){ + pageNum = 1; + } + PageInfo list = adminService.adminPage(adminName, pageNum, pageSize); + return Message.success().add("pageInfo",list); + } + + @RequestMapping("/admin") + public String admin(){ + return "admin/admin"; + } + + @RequestMapping("/adopt") + public String adopt(){ + return "admin/adopt"; + } + + @RequestMapping("/agree") + public String agree(){ + return "admin/agree"; + } + + @RequestMapping("/apply") + public String apply(){ + return "admin/apply"; + } + + @RequestMapping("/blog") + public String blog(){ + return "admin/blog"; + } + + @RequestMapping("/comment") + public String comment(){ + return "admin/comment"; + } + + @RequestMapping("/disAgree") + public String disAgree(){ + return "admin/disAgree"; + } + + @RequestMapping("/pet") + public String pet(){ + return "admin/pet"; + } + + @RequestMapping("/user") + public String user(){ + return "admin/user"; + } + + /*管理员登录*/ + @RequestMapping("/login") + public String login(){ + return "admin/login"; + } + + @RequestMapping("/dologin") + public String doLogin(HttpSession session, String adminName,String adminPwd){ + Admins login = adminService.login(adminName, adminPwd); + if (login == null){ + session.setAttribute("msg","用户名或密码错误!"); + return "redirect:/admin/login"; + } + session.setAttribute("admin",login); + return "redirect:/admin/admin"; + } + + @RequestMapping("/logout") + public String logout(HttpSession session){ + session.invalidate(); + return "redirect:/admin/login"; + } + + @RequestMapping("/developing") + public String developing(){ + return "admin/developing"; + } + +} diff --git a/controller/AnswerController.java b/controller/AnswerController.java new file mode 100644 index 0000000..1bb5873 --- /dev/null +++ b/controller/AnswerController.java @@ -0,0 +1,52 @@ +package club.controller; + +import club.pojo.Answer; +import club.pojo.User; +import club.service.AnswerService; +import club.util.Message; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpSession; +import java.util.List; + +@Controller +@RequestMapping("/answer") +public class AnswerController { + + @Resource + private AnswerService answerService; + + @RequestMapping("/create") + @ResponseBody + public Message create(HttpSession session, Integer commentId, String content){ + User user = (User) session.getAttribute("user"); + Integer integer = answerService.create(user.getId(), commentId, content); + if (integer > 0){ + return Message.success(); + }else { + return Message.fail(); + } + } + + @RequestMapping("/findById") + @ResponseBody + public Message findById(Integer id){ + Answer answer = answerService.findById(id); + return Message.success().add("answer", answer); + } + + @RequestMapping("/creates") + @ResponseBody + public Message creates(HttpSession session, Integer replayId, String content, Integer commentId){ + User user = (User) session.getAttribute("user"); + Integer integer = answerService.creates(user.getId(), replayId, content, commentId); + if (integer > 0){ + return Message.success(); + }else { + return Message.fail(); + } + } +} diff --git a/controller/UserController.java b/controller/UserController.java new file mode 100644 index 0000000..f34fa18 --- /dev/null +++ b/controller/UserController.java @@ -0,0 +1,140 @@ +package club.controller; + +import club.pojo.User; +import club.service.UserService; +import club.util.Message; +import com.github.pagehelper.PageInfo; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import javax.annotation.Resource; +import javax.servlet.http.HttpSession; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +@RequestMapping("/user") +public class UserController { + @Resource + private UserService userService; + + @RequestMapping("/create") + @ResponseBody + public Message add(User user){ + int add = userService.add(user); + if(add>0){ + return Message.success(); + }else{ + return Message.fail(); + } + } + + @RequestMapping("/login") + @ResponseBody + public Message loginuser(HttpSession session, String userName, String password){ + User user = userService.loginuser(userName, password); + if (user != null){ + session.setAttribute("user",user); + return Message.success().add("user",user); + }else{ + return Message.fail(); + } + } + @RequestMapping("/logout") + @ResponseBody + public Message logout(HttpSession session){ + session.invalidate(); + return Message.success(); + } + + @RequestMapping("/users") + @ResponseBody + public Message users(@RequestParam(required = false) String userName, @RequestParam("pn")Integer pageNum){ + Integer pageSize = 4; + PageInfo users = userService.allUser(userName,pageNum,pageSize); + return Message.success().add("pageInfo",users); + } + + @RequestMapping("findById") + @ResponseBody + public Message findById(Integer id){ + User byId = userService.findById(id); + return Message.success().add("user",byId); + } + + @RequestMapping("/delete") + @ResponseBody + public Message del(Integer id){ + int del = userService.del(id); + if(del>0){ + return Message.success(); + }else { + return Message.fail(); + } + } + + @RequestMapping("/about") + public String about(){ + return "user/about"; + } + + @RequestMapping("/error") + public String error(){ + return "user/error"; + } + + @RequestMapping("/index") + public String index(){ + return "user/index"; + } + + @RequestMapping("/personal-info") + public String personalInfo(){ + return "user/personal-info"; + } + + @RequestMapping("/service") + public String service(){ + return "user/service"; + } + + @RequestMapping("/show") + public String show(){ + return "user/show"; + } + + @RequestMapping("/team") + public String team(){ + return "user/team"; + } + + @RequestMapping("/teamBlog") + public String teamBlog(){ + return "user/teamBlog"; + } + + @RequestMapping("/update") + @ResponseBody + public Message update(User user){ + Integer update = userService.update(user); + if(update > 0){ + return Message.success(); + }else { + return Message.fail(); + } + } + + @RequestMapping("/updatePic") + @ResponseBody + public Message updatePic(HttpSession session, MultipartFile file){ + String fileName = FileLoad.uploadUserPic(file); + User user = (User) session.getAttribute("user"); + user.setPic(fileName); + Integer update = userService.update(user); + if (update > 0){ + return Message.success(); + }else { + return Message.fail(); + } + } +} diff --git a/dao/AdminMapper.java b/dao/AdminMapper.java new file mode 100644 index 0000000..89f97ef --- /dev/null +++ b/dao/AdminMapper.java @@ -0,0 +1,8 @@ +package club.dao; + +import club.pojo.Admins; +import com.baomidou.mybatisplus.mapper.BaseMapper; + + +public interface AdminMapper extends BaseMapper { +} diff --git a/dao/AnswerMapper.java b/dao/AnswerMapper.java new file mode 100644 index 0000000..6638f28 --- /dev/null +++ b/dao/AnswerMapper.java @@ -0,0 +1,8 @@ +package club.dao; + +import club.pojo.Answer; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +public interface AnswerMapper extends BaseMapper { + +} diff --git a/dao/UserMapper.java b/dao/UserMapper.java new file mode 100644 index 0000000..a8d91e5 --- /dev/null +++ b/dao/UserMapper.java @@ -0,0 +1,7 @@ +package club.dao; + +import club.pojo.User; +import com.baomidou.mybatisplus.mapper.BaseMapper; + +public interface UserMapper extends BaseMapper { +} \ No newline at end of file diff --git a/pojo/Admins.java b/pojo/Admins.java new file mode 100644 index 0000000..94cb631 --- /dev/null +++ b/pojo/Admins.java @@ -0,0 +1,26 @@ +package club.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; +@Data +public class Admins { + private Integer id; + private String adminName; + private String adminPwd; + private String realName; + private String telephone; + private String email; + //主要是后台到前台的时间格式的转换 + //@JsonFormat注解可以在属性的上方,同样可以在属性对应的get方法上,两种方式没有区别 + @JsonFormat(pattern = "yyyy-MM-dd") + //主要是前后到后台的时间格式的转换 + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date birthday; + private String sex; + private String pic; + private String remark; + +} diff --git a/pojo/Answer.java b/pojo/Answer.java new file mode 100644 index 0000000..2cb8f16 --- /dev/null +++ b/pojo/Answer.java @@ -0,0 +1,28 @@ +package club.pojo; + +import com.baomidou.mybatisplus.annotations.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; +import java.util.Date; + + +@Data +public class Answer { + private Integer id; + private Integer userId; + private Integer replayId; + private Integer commentId; + @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date answerTime; + private String content; + + @TableField(exist = false) + private User user; + @TableField(exist = false) + private Answer answer; + @TableField(exist = false) + private Comment comment; + +} diff --git a/pojo/User.java b/pojo/User.java new file mode 100644 index 0000000..7d1da8c --- /dev/null +++ b/pojo/User.java @@ -0,0 +1,27 @@ +package club.pojo; + +import com.baomidou.mybatisplus.annotations.TableField; +import lombok.Data; + +import java.util.List; + + +@Data +public class User { +// 定义用户类 + private Integer id; + private String userName; + private String password; + private String sex; + private Integer age; + private String telephone; + private String Email; + private String address; + private String pic; + private Integer state; + @TableField(exist = false) + List commentList; + @TableField(exist = false) + List animalList; + +} diff --git a/service/AdminService.java b/service/AdminService.java new file mode 100644 index 0000000..fe9324f --- /dev/null +++ b/service/AdminService.java @@ -0,0 +1,19 @@ +package club.service; + +import club.pojo.Admins; +import com.github.pagehelper.PageInfo; + + +import club.pojo.Admins; +import com.github.pagehelper.PageInfo; + + +public interface AdminService { + PageInfo adminPage(String adminName,Integer pageNum,Integer pageSize); + Admins findById(Integer id); + Admins login(String adminName, String adminPwd); + PageInfo allAdmin(String adminsName, int pageNum, int pageSize); + int add(Admins admins); + int update(Admins admins); + int del(Integer id); +} diff --git a/service/AnswerService.java b/service/AnswerService.java new file mode 100644 index 0000000..af18316 --- /dev/null +++ b/service/AnswerService.java @@ -0,0 +1,12 @@ +package club.service; + +import club.pojo.Answer; + +import java.util.List; + +public interface AnswerService { + List answersAboutOneComment(Integer commentId); + Integer create(Integer userId, Integer commentId, String content); + Answer findById(Integer id); + Integer creates(Integer userId, Integer replayrId, String content, Integer commentId); +} diff --git a/service/UserService.java b/service/UserService.java new file mode 100644 index 0000000..5bf003b --- /dev/null +++ b/service/UserService.java @@ -0,0 +1,23 @@ +package club.service; + +import club.pojo.User; + +import club.pojo.User; +import com.github.pagehelper.PageInfo; + + +import java.util.List; + +public interface UserService { + List findByName(String userName, Integer state); + List showName(String userName); + //登录数据 + User loginuser(String userName,String password); + //添加数据 + int add(User user); + //修改数据 + Integer update(User user); + User findById(Integer id); + PageInfo allUser(String userName, Integer pageNum, Integer pageSize); + int del(Integer id); +} diff --git a/service/impl/AdminServiceImpl.java b/service/impl/AdminServiceImpl.java new file mode 100644 index 0000000..d034d65 --- /dev/null +++ b/service/impl/AdminServiceImpl.java @@ -0,0 +1,66 @@ +package club.service.impl; + +import club.dao.AdminMapper; +import club.pojo.Admins; +import club.service.AdminService; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import java.util.List; + +@Service +@Transactional +public class AdminServiceImpl implements AdminService { + @Resource + private AdminMapper adminMapper; + @Override + public PageInfo adminPage(String adminName, Integer pageNum, Integer pageSize) { + PageHelper.startPage(pageNum,pageSize); + EntityWrapper wrapper = new EntityWrapper(); + if(adminName != null && !"".equals(adminName)){ + wrapper.like("adminName",adminName); + } + List list = adminMapper.selectList(wrapper); + PageInfo pageInfo = new PageInfo<>(list); + return pageInfo; + } + + @Override + public Admins login(String adminName, String adminPwd) { + Admins a = new Admins(); + a.setAdminName(adminName); + Admins admin = adminMapper.selectOne(a); + if (admin != null && admin.getAdminPwd().equals(adminPwd)){ + return admin; + } + return null; + } + + @Override + public PageInfo allAdmin(String adminName, int pageNum, int pageSize) { + return null; + } + + @Override + public int add(Admins admins) { + return adminMapper.insert(admins); + } + + @Override + public int update(Admins admins) { + return adminMapper.updateById(admins); + } + + @Override + public Admins findById(Integer id) { + return adminMapper.selectById(id); + } + + @Override + public int del(Integer id) { + return adminMapper.deleteById(id); + } +} diff --git a/service/impl/AnswerServiceImpl.java b/service/impl/AnswerServiceImpl.java new file mode 100644 index 0000000..1e22d38 --- /dev/null +++ b/service/impl/AnswerServiceImpl.java @@ -0,0 +1,85 @@ +package club.service.impl; + +import club.dao.AnswerMapper; +import club.dao.CommentMapper; +import club.dao.UserMapper; +import club.pojo.Answer; +import club.pojo.Comment; +import club.pojo.User; +import club.service.AnswerService; +import club.service.UserService; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +@Service +@Transactional +public class AnswerServiceImpl implements AnswerService { + + @Resource + private AnswerMapper answerMapper; + + @Resource + private CommentMapper commentMapper; + + @Resource + private UserMapper userMapper; + + @Override + public List answersAboutOneComment(Integer commentId) { + EntityWrapper wrapper = new EntityWrapper(); + if (commentId != null) { + wrapper.eq("commentId", commentId); + } + List list = answerMapper.selectList(wrapper); + if (!list.isEmpty()) { + for (Answer answer : list) { + User user = userMapper.selectById(answer.getUserId()); + answer.setUser(user); + if (answer.getReplayId() != null) { + Answer answer1 = answerMapper.selectById(answer.getReplayId()); + User u = userMapper.selectById(answer1.getUserId()); + answer1.setUser(u); + answer.setAnswer(answer1); + } + } + return list; + }else { + return null; + } + } + + @Override + public Integer create(Integer userId, Integer commentId, String content) { + Answer answer = new Answer(); + answer.setUserId(userId); + answer.setCommentId(commentId); + answer.setContent(content); + answer.setAnswerTime(new Date()); + return answerMapper.insert(answer); + } + + @Override + public Answer findById(Integer id) { + Answer answer = answerMapper.selectById(id); + Comment comment = commentMapper.selectById(answer.getCommentId()); + answer.setComment(comment); + return answer; + } + + @Override + public Integer creates(Integer userId, Integer replayId, String content, Integer commentId) { + Answer answer = new Answer(); + answer.setUserId(userId); + answer.setReplayId(replayId); + answer.setCommentId(commentId); + answer.setContent(content); + answer.setAnswerTime(new Date()); + return answerMapper.insert(answer); + } + +} diff --git a/service/impl/UserServiceImpl.java b/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..78607a9 --- /dev/null +++ b/service/impl/UserServiceImpl.java @@ -0,0 +1,92 @@ +package club.service.impl; + +import club.dao.UserMapper; +import club.pojo.User; +import club.dao.UserMapper; +import club.pojo.Admins; +import club.pojo.User; +import club.service.UserService; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +import java.util.List; +@Service +@Transactional +public class UserServiceImpl implements UserService { + @Resource + private UserMapper userMapper; + @Override + public User findById(Integer id) { + return userMapper.selectById(id); + } + + @Override + public List findByName(String userName, Integer state) { + EntityWrapper wrapper = new EntityWrapper<>(); + if (userName != null && !userName.equals("")){ + wrapper.like("userName", userName); + } + if (state != null){ + wrapper.eq("state", state); + } + return userMapper.selectList(wrapper); + } + + @Override + public List showName(String userName) { + EntityWrapper wrapper = new EntityWrapper(); + if(userName != null && !userName.equals("")){ + wrapper.like("userName",userName); + } + return userMapper.selectList(wrapper); + } + + @Override + public User loginuser(String userName, String password) { + User user = new User(); + user.setUserName(userName); + User user1 = userMapper.selectOne(user); + if (user1 != null && user1.getPassword().equals(password)) { + return user1; + } + return null; + } + + @Override + public Integer update(User user) { + return userMapper.updateById(user); + } + + @Override + public PageInfo allUser(String userName ,Integer pageNum, Integer pageSize) { + PageHelper.startPage(pageNum, pageSize); + EntityWrapper wrapper = new EntityWrapper<>(); + if(userName != null && !"".equals(userName)){ + wrapper.like("userName",userName); + } + + List list = userMapper.selectList(wrapper); + PageInfo pageInfo = new PageInfo<>(list); + return pageInfo; + } + + @Override + public int add(User user) { + return userMapper.insert(user); + } + + @Override + public int del(Integer id) { + return userMapper.deleteById(id); + } +} diff --git a/user.sql b/user.sql new file mode 100644 index 0000000..9bd38cd --- /dev/null +++ b/user.sql @@ -0,0 +1,52 @@ +/* +Navicat MySQL Data Transfer + +Source Server : he +Source Server Version : 50636 +Source Host : localhost:3306 +Source Database : hlb + +Target Server Type : MYSQL +Target Server Version : 50636 +File Encoding : 65001 + +Date: 2024-06-28 13:13:51 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for user +-- ---------------------------- +DROP TABLE IF EXISTS `user`; +CREATE TABLE `user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `userName` varchar(20) NOT NULL, + `password` varchar(30) NOT NULL, + `sex` varchar(2) DEFAULT NULL COMMENT '性别', + `age` int(11) DEFAULT NULL COMMENT '年龄', + `telephone` varchar(20) DEFAULT NULL COMMENT '电话', + `Email` varchar(30) DEFAULT NULL COMMENT 'Email', + `address` varchar(50) DEFAULT NULL COMMENT '地址', + `pic` varchar(100) DEFAULT 't0.jpg', + `state` int(11) DEFAULT '0' COMMENT '有无领养宠物的经历 0 是没有 1 是由', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; + +-- ---------------------------- +-- Records of user +-- ---------------------------- +INSERT INTO `user` VALUES ('1', 'tzp', '11', '男', '10', '13809182091', '', '攀枝花', 't1.jpg', '3'); +INSERT INTO `user` VALUES ('2', '打瞌睡', '11', '男', '50', '13908457344', '', '泸州', 't2.jpg', '0'); +INSERT INTO `user` VALUES ('3', '能理解', '11', '男', '45', '13903827601', '132121129281@qq.com', '泸州', 't3.jpg', '1'); +INSERT INTO `user` VALUES ('4', '云集了', '11', '男', '43', '13903822001', '', '泸州', 't4.jpg', '1'); +INSERT INTO `user` VALUES ('5', '洋溢', '11', '女', '23', '13903810621', '121212549281@qq.com', '泸州', 't5.jpg', '1'); +INSERT INTO `user` VALUES ('6', '陈一', '11', '男', '40', '13903819146', '12121212181@qq.com', '泸州', 't6.jpg', '0'); +INSERT INTO `user` VALUES ('8', '陈二', '11', '女', '35', '13123819301', '12121212112@qq.com', '泸州', 't8.jpg', '0'); +INSERT INTO `user` VALUES ('17', '陈三', '11', '女', '32', '15797959509', '21111111111@qq.com', '泸州', 't17.jpg', '0'); +INSERT INTO `user` VALUES ('33', '沉思', '11', '男', '22', '1456879876', '1111111118@163.com', '泸州', 'xq1.jpg', '1'); +INSERT INTO `user` VALUES ('34', '晨雾', '11', '男', '22', '1456879876', '1111111118@163.com', '泸州', 'xq2.jpg', '0'); +INSERT INTO `user` VALUES ('35', 'eqw', '123456', '男', '123', 'ewqeqwe', 'qeweqw', 'qeweqw', 't0.jpg', '0'); +INSERT INTO `user` VALUES ('36', '123', '123', '男', '12', '16565', '257451', '好几个', 't0.jpg', '0'); +INSERT INTO `user` VALUES ('37', '1', '1', '男', '2', '23124', '21', '123', 't0.jpg', '0'); +INSERT INTO `user` VALUES ('38', 'lll', '1234', '男', '22', '15281210084', '2802045328@qq.cpm', '孝泉', 't0.jpg', '0'); diff --git a/util/Message.java b/util/Message.java new file mode 100644 index 0000000..2821c6e --- /dev/null +++ b/util/Message.java @@ -0,0 +1,68 @@ +package club.util; + +import java.util.HashMap; +import java.util.Map; + + +// +//工具包 +public class Message { + + /** + * 状态码 100-成功 200-失败 + * */ + private int code; + + /** + * 提示信息 + * */ + private String message; + + /** + * 用户要返回给浏览器的数据 + * */ + private Map extend = new HashMap(); + + public static Message success(){ + Message result = new Message(); + result.setCode(100); + result.setMessage("处理成功!"); + return result; + } + + public static Message fail(){ + Message result = new Message(); + result.setCode(200); + result.setMessage("处理失败!"); + return result; + } + + public Message add(String key,Object value){ + this.getExtend().put(key, value); + return this; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Map getExtend() { + return extend; + } + + public void setExtend(Map extend) { + this.extend = extend; + } +}