├── .gitattributes ├── .gitignore ├── BBS.iml ├── README.md ├── forum.sql ├── pom.xml └── src └── main ├── java ├── aop │ ├── LogAspect.java │ ├── MessageAspect.java │ └── VisitorAspect.java ├── controller │ ├── LoginLogController.java │ ├── MainController.java │ ├── MessageController.java │ ├── ReplyController.java │ ├── TopicController.java │ └── UserController.java ├── dao │ ├── LoginLogMapper.java │ ├── MessageMapper.java │ ├── ReplyMapper.java │ ├── TabMapper.java │ ├── TopicMapper.java │ ├── UserMapper.java │ └── VisitorMapper.java ├── intercepter │ └── CORSFilter.java ├── mapper │ ├── LoginLogMapper.xml │ ├── MessageMapper.xml │ ├── ReplyMapper.xml │ ├── TabMapper.xml │ ├── TopicMapper.xml │ ├── UserMapper.xml │ └── VisitorMapper.xml ├── pojo │ ├── LoginLog.java │ ├── Message.java │ ├── Reply.java │ ├── Tab.java │ ├── Topic.java │ ├── User.java │ └── Visitor.java ├── service │ ├── Impl │ │ ├── LoginLogServiceImpl.java │ │ ├── MessageServiceImpl.java │ │ ├── ReplyServiceImpl.java │ │ ├── TabServiceImpl.java │ │ ├── TopicServiceImpl.java │ │ ├── UserServiceImpl.java │ │ └── VisitorServiceImpl.java │ ├── LoginLogService.java │ ├── MessageService.java │ ├── ReplyService.java │ ├── TabService.java │ ├── TopicService.java │ ├── UserService.java │ └── VisitorService.java ├── test │ ├── test.java │ ├── testLog4j.java │ ├── testlog.java │ ├── testsignup.java │ └── testtopic.java └── util │ ├── HexConversion.java │ ├── Page.java │ └── ProduceMD5.java ├── resources ├── applicationContext.xml ├── jdbc.properties ├── log │ └── Lhfly.log ├── log4j.properties ├── mybatis-config.xml └── springMVC.xml └── webapp ├── WEB-INF ├── jsp │ ├── 404.jsp │ ├── cate.jsp │ ├── detail.jsp │ ├── footer.jsp │ ├── header.jsp │ ├── message.jsp │ ├── new.jsp │ ├── page.jsp │ ├── settings.jsp │ ├── side.jsp │ ├── signin.jsp │ ├── signup.jsp │ ├── update_avatar.jsp │ └── user_info.jsp └── web.xml └── static ├── css ├── bootstrap.min.css ├── front-common.css └── front-footer.css ├── img ├── avatar │ ├── 1521949392720-2.PNG │ ├── avatar-default-1.png │ ├── avatar-default-10.png │ ├── avatar-default-11.png │ ├── avatar-default-2.png │ ├── avatar-default-3.png │ ├── avatar-default-4.png │ ├── avatar-default-5.png │ ├── avatar-default-6.png │ ├── avatar-default-7.png │ ├── avatar-default-8.png │ └── avatar-default-9.png ├── background │ └── timg.jpg └── icon │ ├── heart.svg │ └── magnifying-glass.svg └── js ├── bootstrap.min.js ├── jquery-3.2.1.js └── js.cookie.js /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sql linguist-language=java -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .log 2 | BBS.iml -------------------------------------------------------------------------------- /BBS.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | file://$MODULE_DIR$/src/main/resources/applicationContext.xml 18 | file://$MODULE_DIR$/src/main/resources/springMVC.xml 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Lhfly-BBS 论坛 2 | 3 | 受GitHub的一个BBS项目Genesis的启发,重新写了一个BBS论坛,实现了基本功能 4 | ##### 技术栈 5 | 6 | * 本项目基于Spring、Spring MVC、MyBatis框架实现 7 | * 数据库采用MySql 5.7.22 8 | * 前端采用HTML、CSS、jQuery、Bootstrap 9 | 10 | ##### 功能实现 11 | 12 | * 发布主题、回复主题 13 | * 按照活跃度、最后更新时间、是否为精品对帖子进行排序展示 14 | * 管理员账户能够实现设置主题为精品、删除主题、删除回复功能 15 | * 后天统计访客信息、统计用户登陆信息 16 | * 用户登陆与注册、用户信息界面展示、用户修改头像 17 | * 回复消息后发帖者能够收到消息提醒、未读消息和已读消息展示 18 | * 在页面展示全站最热议的主题 19 | * 用户发帖、登陆、回帖行为的积分系统 20 | * 翻页功能 21 | 22 | ##### 待更新的功能 23 | 24 | * 使用Redis实现缓存 25 | * 发帖人编辑主题 26 | * 使用Nginx实现动静分离、负载均衡 27 | * 可以发送图片 28 | * 用户回帖记录展示 29 | * 主题里用户之间的回复 30 | 31 | ##### 界面展示 32 | 33 | 首页 34 | ![微信截图_20191017204848.png](https://i.loli.net/2019/10/17/jse3GRl4Npkhr5g.png) 35 | 36 | 发帖界面 37 | ![微信截图_20191017205022.png](https://i.loli.net/2019/10/17/Mo9AB4fOWqbctPw.png) 38 | 39 | 用户信息界面 40 | ![微信截图_20191017205044.png](https://i.loli.net/2019/10/17/OCMEWNpb2DFmzRw.png) 41 | 42 | 用户消息列表 43 | ![微信截图_20191017205011.png](https://i.loli.net/2019/10/17/XGohLU24Wmkxby5.png) 44 | 45 | 主题详情 46 | ![微信截图_20191017204928.png](https://i.loli.net/2019/10/17/yAUk7D6finR18jF.png) 47 | 48 | 管理员的主题详情界面 49 | ![微信截图_20191017204948.png](https://i.loli.net/2019/10/17/DvEIS4utr3RlQjn.png) 50 | 51 | 网站信息展示 52 | ![微信截图_20191017212355.png](https://i.loli.net/2019/10/17/JHWnvM9uCYQ2qoa.png) -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | bupt 8 | BBS 9 | 1.0-SNAPSHOT 10 | war 11 | 12 | 13 | UTF-8 14 | UTF-8 15 | 4.2.2.RELEASE 16 | 5.1.29 17 | 3.0-alpha-1 18 | 1.8.1 19 | 1.9 20 | 1.4 21 | 5.0.2.Final 22 | 8.1.8.v20121106 23 | 6.8.7 24 | 25 | 26 | 27 | org.springframework 28 | spring-beans 29 | ${spring.version} 30 | 31 | 32 | org.springframework 33 | spring-aop 34 | ${spring.version} 35 | 36 | 37 | org.springframework 38 | spring-context 39 | ${spring.version} 40 | 41 | 42 | org.springframework 43 | spring-context-support 44 | ${spring.version} 45 | 46 | 47 | org.springframework 48 | spring-jdbc 49 | ${spring.version} 50 | 51 | 52 | org.springframework 53 | spring-webmvc 54 | ${spring.version} 55 | 56 | 57 | 58 | commons-dbcp 59 | commons-dbcp 60 | ${commons-dbcp.version} 61 | 62 | 63 | mysql 64 | mysql-connector-java 65 | ${mysql.version} 66 | 67 | 68 | javax.servlet 69 | servlet-api 70 | ${servlet.version} 71 | provided 72 | 73 | 74 | org.aspectj 75 | aspectjweaver 76 | ${aspectj.version} 77 | 78 | 79 | 80 | cglib 81 | cglib 82 | 2.2.2 83 | 84 | 85 | 86 | org.slf4j 87 | slf4j-log4j12 88 | 1.7.25 89 | 90 | 91 | 92 | org.testng 93 | testng 94 | ${testng.version} 95 | test 96 | 97 | 98 | org.springframework 99 | spring-test 100 | ${spring.version} 101 | test 102 | 103 | 104 | 105 | javax.servlet 106 | jstl 107 | 1.2 108 | 109 | 110 | org.mybatis 111 | mybatis 112 | 3.4.4 113 | 114 | 115 | org.mybatis 116 | mybatis-spring 117 | 1.3.0 118 | 119 | 120 | 121 | commons-codec 122 | commons-codec 123 | 1.10 124 | 125 | 126 | 127 | 128 | com.alibaba 129 | druid 130 | 1.0.29 131 | 132 | 133 | 134 | com.fasterxml.jackson.core 135 | jackson-core 136 | 2.9.10 137 | 138 | 139 | com.fasterxml.jackson.core 140 | jackson-annotations 141 | 2.9.10 142 | 143 | 144 | com.fasterxml.jackson.core 145 | jackson-databind 146 | 2.9.10.1 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | com.github.pagehelper 158 | pagehelper 159 | 5.1.2 160 | 161 | 162 | 163 | 164 | redis.clients 165 | jedis 166 | 2.9.0 167 | 168 | 169 | org.springframework.data 170 | spring-data-redis 171 | 2.0.0.RELEASE 172 | 173 | 174 | 175 | log4j 176 | log4j 177 | 1.2.17 178 | 179 | 180 | 181 | commons-fileupload 182 | commons-fileupload 183 | 1.3.3 184 | 185 | 186 | commons-io 187 | commons-io 188 | 2.6 189 | 190 | 191 | 192 | 193 | org.apache.shiro 194 | shiro-core 195 | 1.4.0 196 | 197 | 198 | 199 | 200 | junit 201 | junit 202 | 4.12 203 | test 204 | 205 | 206 | 207 | 208 | commons-lang 209 | commons-lang 210 | 2.6 211 | 212 | 213 | eu.bitwalker 214 | UserAgentUtils 215 | 1.20 216 | 217 | 218 | 219 | 220 | 221 | Genesis 222 | 223 | 224 | 225 | org.mortbay.jetty 226 | maven-jetty-plugin 227 | 6.1.25 228 | 229 | 230 | 231 | 8080 232 | 60000 233 | 234 | 235 | / 236 | 0 237 | 238 | 239 | 240 | 241 | org.apache.maven.plugins 242 | maven-surefire-plugin 243 | 2.19.1 244 | 245 | methods 246 | 10 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | src/main/java 255 | 256 | **/*.xml 257 | 258 | 259 | 260 | 263 | 264 | 265 | -------------------------------------------------------------------------------- /src/main/java/aop/LogAspect.java: -------------------------------------------------------------------------------- 1 | package aop; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.aspectj.lang.JoinPoint; 5 | import org.aspectj.lang.annotation.Aspect; 6 | import org.aspectj.lang.annotation.Before; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.Arrays; 10 | 11 | /** 12 | * 日志写入,路径在log4j.properties中有 13 | */ 14 | @Component 15 | @Aspect 16 | public class LogAspect { 17 | private final static Logger logger= Logger.getLogger(LogAspect.class); 18 | 19 | 20 | @Before("execution(* controller.*.*(..))") 21 | public void loginLogAspect(JoinPoint joinPoint) throws InterruptedException { 22 | String methodName=joinPoint.getSignature().toShortString(); 23 | String args= Arrays.toString(joinPoint.getArgs()); 24 | logger.info("---Before method "+methodName+" invoke, param:" +args+"---"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/aop/MessageAspect.java: -------------------------------------------------------------------------------- 1 | package aop; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.annotation.After; 5 | import org.aspectj.lang.annotation.AfterReturning; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.context.request.RequestContextHolder; 10 | import org.springframework.web.context.request.ServletRequestAttributes; 11 | import org.springframework.web.servlet.ModelAndView; 12 | import pojo.Message; 13 | import pojo.Reply; 14 | import pojo.Topic; 15 | import pojo.User; 16 | import service.MessageService; 17 | import service.ReplyService; 18 | import service.TopicService; 19 | import service.UserService; 20 | 21 | import javax.servlet.http.HttpServletRequest; 22 | import java.util.Date; 23 | 24 | /** 25 | * 插入消息列 26 | */ 27 | @Component 28 | @Aspect 29 | public class MessageAspect { 30 | @Autowired 31 | MessageService messageService; 32 | @Autowired 33 | UserService userService; 34 | @Autowired 35 | TopicService topicService; 36 | //当添加了reply后,获取从后台返回的ModelAndView 37 | @AfterReturning(returning = "view",pointcut = "execution(* controller.ReplyController.addReply(..))") 38 | public void insertMessage(Object view){ 39 | HttpServletRequest request= ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 40 | Integer topicId=Integer.parseInt(request.getParameter("topicId")); 41 | Topic topic =topicService.selectById(topicId); 42 | Integer replyUserId=Integer.parseInt(request.getParameter("replyUserId")); 43 | Reply reply= (Reply) ((ModelAndView)view).getModel().get("reply"); 44 | //创建message 45 | Message message=new Message(); 46 | message.setAction("1"); 47 | message.setContext(reply.getContent()); 48 | message.setCreate_time(reply.getCreateTime()); 49 | message.setIs_read(0); 50 | message.setType("0"); 51 | message.setTopic_id(topicId); 52 | message.setSender_id(replyUserId); 53 | message.setUser_id(topic.getUserId()); 54 | message.setReply_id(reply.getId()); 55 | 56 | messageService.insert(message); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/aop/VisitorAspect.java: -------------------------------------------------------------------------------- 1 | package aop; 2 | 3 | import eu.bitwalker.useragentutils.UserAgent; 4 | import org.aspectj.lang.annotation.Aspect; 5 | import org.aspectj.lang.annotation.Before; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.context.request.RequestContextHolder; 9 | import org.springframework.web.context.request.ServletRequestAttributes; 10 | import pojo.Visitor; 11 | import service.VisitorService; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import java.util.Date; 15 | 16 | /** 17 | * 在进行topic的相关操作时向数据库添加访问操作 18 | */ 19 | @Component 20 | @Aspect 21 | public class VisitorAspect { 22 | @Autowired 23 | VisitorService visitorService; 24 | @Before("execution(* controller.TopicController.*(..))") 25 | public void addVisitorAspect(){ 26 | Visitor visitor=new Visitor(); 27 | HttpServletRequest request= ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 28 | String ip = request.getHeader("x-forwarded-for"); 29 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 30 | ip = request.getHeader("Proxy-Client-IP"); 31 | } 32 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 33 | ip = request.getHeader("WL-Proxy-Client-IP"); 34 | } 35 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 36 | ip = request.getHeader("HTTP_CLIENT_IP"); 37 | } 38 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 39 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 40 | } 41 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 42 | ip = request.getRemoteAddr(); 43 | } 44 | UserAgent userAgent=UserAgent.parseUserAgentString(request.getHeader("User-Agent")); 45 | //获取用户浏览器名 46 | String userbrowser=userAgent.getBrowser().toString(); 47 | visitor.setIP(ip); 48 | visitor.setDevice(userbrowser); 49 | visitor.setVisitTime(new Date()); 50 | 51 | visitorService.insert(visitor); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/controller/LoginLogController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | 5 | @Controller 6 | public class LoginLogController { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/controller/MainController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.servlet.ModelAndView; 7 | import pojo.Tab; 8 | import service.*; 9 | 10 | import java.util.List; 11 | 12 | @Controller 13 | public class MainController { 14 | @Autowired 15 | TopicService topicService; 16 | @Autowired 17 | ReplyService replyService; 18 | @Autowired 19 | TabService tabService; 20 | @Autowired 21 | UserService userService; 22 | @Autowired 23 | VisitorService visitorService; 24 | /** 25 | * 进入登陆页面 26 | */ 27 | @RequestMapping("/signin") 28 | public ModelAndView signin(){ 29 | ModelAndView mv=new ModelAndView("signin"); 30 | 31 | //获取统计信息 32 | int topicsNum=topicService.getTopicsNum(); 33 | int userNum=userService.getUserCount(); 34 | //获取访问量 35 | Integer visitorNum=visitorService.countVisitor(); 36 | mv.addObject("topicsNum", topicsNum); 37 | mv.addObject("usersNum", userNum); 38 | mv.addObject("visitorNum",visitorNum); 39 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 40 | return mv; 41 | } 42 | /** 43 | * 进入注册界面 44 | */ 45 | @RequestMapping("/signup") 46 | public ModelAndView signup(){ 47 | ModelAndView mv=new ModelAndView("signup"); 48 | 49 | //获取统计信息 50 | int topicsNum=topicService.getTopicsNum(); 51 | int usersNum=userService.getUserCount(); 52 | //获取访问量 53 | Integer visitorNum=visitorService.countVisitor(); 54 | mv.addObject("topicsNum",topicsNum); 55 | mv.addObject("usersNum",usersNum); 56 | mv.addObject("visitorNum",visitorNum); 57 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 58 | return mv; 59 | } 60 | /** 61 | * 进入新建主题界面 62 | */ 63 | @RequestMapping("/new") 64 | public ModelAndView newTopic(){ 65 | ModelAndView mv=new ModelAndView("new"); 66 | List tabs=tabService.getAllTabs(); 67 | //获取统计信息 68 | int topicsNum=topicService.getTopicsNum(); 69 | int usersNum=userService.getUserCount(); 70 | //获取访问量 71 | Integer visitorNum=visitorService.countVisitor(); 72 | mv.addObject("tabs",tabs); 73 | mv.addObject("topicsNum",topicsNum); 74 | mv.addObject("usersNum",usersNum); 75 | mv.addObject("visitorNum",visitorNum); 76 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 77 | return mv; 78 | } 79 | /** 80 | * 配置404界面 81 | */ 82 | @RequestMapping("*") 83 | public String notFind(){ 84 | return "404"; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/controller/MessageController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.servlet.ModelAndView; 10 | import pojo.Message; 11 | import pojo.Topic; 12 | import pojo.User; 13 | import service.*; 14 | import util.Page; 15 | 16 | import javax.servlet.http.HttpSession; 17 | import java.util.List; 18 | 19 | @Controller 20 | public class MessageController { 21 | @Autowired 22 | UserService userService; 23 | @Autowired 24 | LoginLogService loginLogService; 25 | @Autowired 26 | TopicService topicService; 27 | @Autowired 28 | VisitorService visitorService; 29 | @Autowired 30 | MessageService messageService; 31 | 32 | @RequestMapping("/message/{userId}") 33 | public ModelAndView getMessage(@PathVariable("userId")Integer userId 34 | , HttpSession session, Page page){ 35 | ModelAndView mv=new ModelAndView("message"); 36 | //获取第1页,10条内容,默认查询总数count 37 | PageHelper.offsetPage(page.getStart(),page.getCount()); 38 | List messages=messageService.getAllMessage(userId); 39 | 40 | //分页 41 | int total= (int) new PageInfo(messages).getTotal(); 42 | page.setTotal(total); 43 | //获取统计信息 44 | int topicsNum=topicService.getTopicsNum(); 45 | int usersNum=userService.getUserCount(); 46 | 47 | //获取用户信息 48 | Integer uid= (Integer) session.getAttribute("userId"); 49 | User user=userService.getUserById(uid); 50 | //获取访问量 51 | Integer visitorNum=visitorService.countVisitor(); 52 | //最热主题 53 | List hotestTopics=topicService.listMostCommentsTopics(); 54 | //把user查出来赋值给message中的sender 55 | for(int i=0;i topics=topicService.listTopicsAndUsers(); 49 | //分页 50 | int total= (int) new PageInfo(topics).getTotal(); 51 | page.setTotal(total); 52 | 53 | //获取统计信息 54 | int topicsNum=topicService.getTopicsNum(); 55 | int usersNum=userService.getUserCount(); 56 | 57 | //获取用户信息 58 | Integer uid=(Integer)session.getAttribute("userId"); 59 | User user=userService.getUserById(uid); 60 | //获取访问量 61 | Integer visitorNum=visitorService.countVisitor(); 62 | //热门主题 63 | List hotestTopics=topicService.listMostCommentsTopics(); 64 | modelAndView.addObject("topics", topics); 65 | modelAndView.addObject("hotestTopics", hotestTopics); 66 | modelAndView.addObject("topicsNum", topicsNum); 67 | modelAndView.addObject("usersNum", usersNum); 68 | modelAndView.addObject("user", user); 69 | modelAndView.addObject("visitorNum", visitorNum); 70 | modelAndView.addObject("page", page); 71 | modelAndView.addObject("todayVisitor", visitorService.todayVisitor()); 72 | modelAndView.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 73 | return modelAndView; 74 | } 75 | /** 76 | * 加载主题详细页面 77 | */ 78 | @RequestMapping("/t/{id}") 79 | public ModelAndView toTopic(@PathVariable("id")int id,HttpSession session){ 80 | //先检验这个帖子是否存在 81 | if(!topicService.existTopic(id)){ 82 | //不存在跳转到404界面 83 | return new ModelAndView("404"); 84 | } 85 | //点击量+1 86 | boolean ifSuccess=topicService.clickAddOne(id); 87 | //获取主题信息 88 | Topic topic=topicService.selectById(id); 89 | //获取主题全部评论 90 | List replies=replyService.getRepliesOfTopic(id); 91 | //获取评论数 92 | int repliesNum=replyService.repliesNum(id); 93 | //获取统计信息 94 | int topicsNum=topicService.getTopicsNum(); 95 | int usersNum=userService.getUserCount(); 96 | //获取用户信息 97 | Integer uid= (Integer) session.getAttribute("userId"); 98 | User user=userService.getUserById(uid); 99 | //最热主题 100 | List hotestTopics=topicService.listMostCommentsTopics(); 101 | //获取访问量 102 | Integer visitorNum=visitorService.countVisitor(); 103 | 104 | ModelAndView topicPage=new ModelAndView("detail"); 105 | topicPage.addObject("topic", topic); 106 | topicPage.addObject("replies", replies); 107 | topicPage.addObject("repliesNum",repliesNum); 108 | topicPage.addObject("topicsNum",topicsNum); 109 | topicPage.addObject("usersNum",usersNum); 110 | topicPage.addObject("user",user); 111 | topicPage.addObject("hotestTopics",hotestTopics); 112 | topicPage.addObject("visitorNum",visitorNum); 113 | topicPage.addObject("todayVisitor", visitorService.todayVisitor()); 114 | topicPage.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 115 | return topicPage; 116 | } 117 | /** 118 | * 加载指定板块 119 | */ 120 | @RequestMapping("/tab/{tabNameEn}") 121 | public ModelAndView toTabPage(@PathVariable("tabNameEn")String tabNameEn,HttpSession session,Page page){ 122 | Tab tab=tabService.getByTabNameEn(tabNameEn); 123 | Integer tabId=tab.getId(); 124 | 125 | ModelAndView mv=new ModelAndView("cate"); 126 | //获取第1页,10条内容,默认查询总数count 127 | PageHelper.offsetPage(page.getStart(),page.getCount()); 128 | //全部主题 129 | List topics=topicService.listTopicsAndUsersOfTab(tabId); 130 | //分页 131 | int total= (int) new PageInfo(topics).getTotal(); 132 | page.setTotal(total); 133 | 134 | //获取统计信息 135 | int topicsNum=topicService.getTopicsNum(); 136 | int usersNum=userService.getUserCount(); 137 | //获取用户信息 138 | Integer uid= (Integer) session.getAttribute("userId"); 139 | User user=userService.getUserById(uid); 140 | 141 | List hotestTopics=topicService.listMostCommentsTopics(); 142 | //获取访问量 143 | Integer visitorNum=visitorService.countVisitor(); 144 | mv.addObject("topics", topics); 145 | mv.addObject("topicsNum", topicsNum); 146 | mv.addObject("usersNum", usersNum); 147 | mv.addObject("tab", tab); 148 | mv.addObject("user", user); 149 | mv.addObject("hotestTopics", hotestTopics); 150 | mv.addObject("visitorNum",visitorNum); 151 | mv.addObject("page", page); 152 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 153 | mv.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 154 | return mv; 155 | } 156 | /** 157 | * 发表主题 158 | */ 159 | @RequestMapping(value = "/topic/add",method = RequestMethod.POST) 160 | public ModelAndView addTopic(HttpServletRequest request,HttpSession session){ 161 | ModelAndView mv; 162 | //未登录 163 | if(session.getAttribute("userId")==null){ 164 | mv=new ModelAndView("redirect:/signin"); 165 | return mv; 166 | } 167 | //处理参数 168 | Integer userId= (Integer) session.getAttribute("userId"); 169 | String title=request.getParameter("title"); 170 | String content=request.getParameter("content"); 171 | Byte tabId=Byte.parseByte(request.getParameter("tab")); 172 | //新建topic 173 | Topic topic=new Topic(); 174 | topic.setUserId(userId); 175 | topic.setTitle(title); 176 | topic.setContent(content); 177 | topic.setTabId(tabId); 178 | topic.setCreateTime(new Date()); 179 | topic.setUpdateTime(new Date()); 180 | //添加topic 181 | boolean ifSucc=topicService.addTopic(topic); 182 | userService.addCredit(1,userId); 183 | mv=new ModelAndView("redirect:/"); 184 | return mv; 185 | } 186 | /** 187 | * 活跃/精华/最近 版面的跳转中转 188 | */ 189 | @RequestMapping("/topic/{classifyName}") 190 | public String temp(@PathVariable("classifyName")String classifyName,HttpServletRequest request){ 191 | String tabNameEn=request.getHeader("Referer"); 192 | if(tabNameEn.contains("tab")){ 193 | int index=tabNameEn.lastIndexOf("/"); 194 | tabNameEn=tabNameEn.substring(index+1); 195 | //如果在具体某个tab上就转到对应的界面 196 | return "redirect:/topictab/"+classifyName+"/"+tabNameEn; 197 | }else { 198 | //如果不在具体某个tab上,就把tabName写为all 199 | return "redirect:/topictab/"+classifyName+"/all"; 200 | } 201 | } 202 | /** 203 | * 每个版面都要有自己相应的 活跃/精华/最近 204 | * @param classifyName 205 | * @param session 206 | * @return 207 | */ 208 | @RequestMapping("/topictab/{classifyName}/{tabNameEn}") 209 | public ModelAndView classify(@PathVariable("classifyName")String classifyName,@PathVariable("tabNameEn")String tabNameEn,HttpSession session,Page page){ 210 | List topics; 211 | //获取第1页,10条内容,默认查询总数count 212 | PageHelper.offsetPage(page.getStart(),page.getCount()); 213 | if(!tabNameEn.equals("all")){ 214 | //获取版面信息 215 | Tab tab=tabService.getByTabNameEn(tabNameEn); 216 | Integer tabId=tab.getId(); 217 | if(classifyName.equals("active")){ 218 | //获取活跃主题 219 | topics=topicService.listActiveTopics(tabId); 220 | }else if(classifyName.equals("essence")){ 221 | //获取精品主题主题 222 | topics=topicService.listEssenceTopics(tabId); 223 | }else{ 224 | //获取最近主题 225 | topics=topicService.listRecentTopics(tabId); 226 | } 227 | 228 | }else { 229 | if(classifyName.equals("active")){ 230 | //获取活跃主题 231 | topics=topicService.listAllActiveTopics(); 232 | }else if(classifyName.equals("essence")){ 233 | //获取精品主题主题 234 | topics=topicService.listAllEssenceTopics(); 235 | }else{ 236 | //获取最近主题 237 | topics=topicService.listAllRecentTopics(); 238 | } 239 | } 240 | int total= (int) new PageInfo(topics).getTotal(); 241 | page.setTotal(total); 242 | //获取统计信息 243 | int topicsNum=topicService.getTopicsNum(); 244 | int usersNum=userService.getUserCount(); 245 | //获取用户信息 246 | Integer uid= (Integer) session.getAttribute("userId"); 247 | User user=userService.getUserById(uid); 248 | //获取热门主题 249 | List hotestTopics=topicService.listMostCommentsTopics(); 250 | //获取访问量 251 | Integer visitorNum=visitorService.countVisitor(); 252 | ModelAndView mv=new ModelAndView("cate"); 253 | mv.addObject("topics", topics); 254 | mv.addObject("topicsNum", topicsNum); 255 | mv.addObject("usersNum", usersNum); 256 | mv.addObject("user", user); 257 | mv.addObject("hotestTopics", hotestTopics); 258 | mv.addObject("visitorNum",visitorNum); 259 | mv.addObject("page", page); 260 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 261 | mv.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 262 | return mv; 263 | } 264 | //删除主题 265 | @RequestMapping("/topic/delete/{topicId}") 266 | @Transactional 267 | public String delete(@PathVariable("topicId")Integer topicId){ 268 | replyService.deleteByTopicId(topicId); 269 | topicService.deleteByPrimaryKey(topicId); 270 | return "redirect:/"; 271 | } 272 | //给主题取消精品 273 | @RequestMapping("/topic/cancelEssence/{topicId}") 274 | public String cancelEssence(@PathVariable("topicId")Integer topicId){ 275 | Topic topic=topicService.selectById(topicId); 276 | topic.setIsEssence(0); 277 | topicService.updateByPrimaryKeySelective(topic); 278 | return "redirect:/t/"+topicId; 279 | } 280 | //给主题加精品 281 | @RequestMapping("/topic/addEssence/{topicId}") 282 | public String addEssence(@PathVariable("topicId")Integer topicId){ 283 | Topic topic=topicService.selectById(topicId); 284 | topic.setIsEssence(1); 285 | topicService.updateByPrimaryKeySelective(topic); 286 | return "redirect:/t/"+topicId; 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/main/java/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import eu.bitwalker.useragentutils.UserAgent; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.*; 7 | import org.springframework.web.multipart.MultipartFile; 8 | import org.springframework.web.servlet.ModelAndView; 9 | import pojo.LoginLog; 10 | import pojo.Topic; 11 | import pojo.User; 12 | import service.*; 13 | import util.ProduceMD5; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpSession; 17 | import java.io.File; 18 | import java.util.Date; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Random; 22 | 23 | @Controller 24 | public class UserController { 25 | @Autowired 26 | UserService userService; 27 | @Autowired 28 | LoginLogService loginLogService; 29 | @Autowired 30 | TopicService topicService; 31 | @Autowired 32 | VisitorService visitorService; 33 | @Autowired 34 | MessageService messageService; 35 | //用户注册 36 | @RequestMapping("/user/add/do") 37 | public String addUser(HttpServletRequest request,HttpSession session){ 38 | String username=request.getParameter("username"); 39 | //如果存在就返回到注册页面 40 | if(userService.existUsername(username)){ 41 | request.setAttribute("errorMessage","You are the best"); 42 | //TODO: 校验 43 | // return "redirect:/signup/{errorMessage}"; 44 | return "redirect:/signup"; 45 | } 46 | 47 | //新建user对象 48 | User user=new User(); 49 | String phoneNum=request.getParameter("tel"); 50 | String areaCode=request.getParameter("areaCode"); 51 | String phone=areaCode+phoneNum; 52 | //用户类型 53 | Byte type=new Byte("0"); 54 | //密码加密处理 55 | String password= ProduceMD5.getMD5(request.getParameter("password")); 56 | //生成随机数,用于生成头像URL 57 | Random random=new Random(); 58 | int randomNum=random.nextInt(10)+1; 59 | String avatarUrl="/img/avatar/avatar-default-"+randomNum+".png"; 60 | //初始化User对象 61 | user.setUsername(request.getParameter("username")); 62 | user.setPassword(password); 63 | user.setEmail(request.getParameter("email")); 64 | user.setPhoneNum(phone); 65 | user.setCreateTime(new Date()); 66 | user.setUpdateTime(new Date()); 67 | user.setCredit(0); 68 | user.setType(type); 69 | user.setAvatar(avatarUrl); 70 | 71 | boolean success=userService.addUser(user); 72 | System.out.println(success); 73 | return "redirect:/"; 74 | 75 | } 76 | /** 77 | * 用户登陆 ajax从后台发送请求验证 78 | * @param request 79 | * @param session 80 | * @return 0:用户名不存在 1:密码错误 2:登录成功 81 | */ 82 | @RequestMapping("/api/loginCheck") 83 | @ResponseBody 84 | public Object signin(HttpServletRequest request, HttpSession session){ 85 | //处理参数 86 | String password=ProduceMD5.getMD5(request.getParameter("password")); 87 | String username=request.getParameter("username"); 88 | //验证用户名密码 89 | int loginVerify=userService.login(username,password); 90 | 91 | HashMap res=new HashMap(); 92 | 93 | //登陆成功 94 | if(loginVerify==2){ 95 | User user=userService.getUserByUsername(username); 96 | Integer userId=user.getId(); 97 | //添加积分 98 | boolean ifSuccAddCredit=userService.addCredit(1, userId); 99 | //用户信息写入session 100 | session.setAttribute("userId",userId); 101 | session.setAttribute("username", username); 102 | //获取登陆信息 103 | String ip=getRemortIP(request); 104 | UserAgent userAgent=UserAgent.parseUserAgentString(request.getHeader("User-Agent")); 105 | //获取用户浏览器名 106 | String userbrowser=userAgent.getBrowser().toString(); 107 | //写入登陆日志 108 | LoginLog log=new LoginLog(); 109 | log.setDevice(userbrowser); 110 | log.setDevice(userbrowser); 111 | log.setUserId(userId); 112 | log.setIp(ip); 113 | log.setLoginTime(new Date()); 114 | boolean ifSuccAddLog=loginLogService.addLoginLog(log); 115 | 116 | res.put("stateCode","2"); 117 | } 118 | //密码错误 119 | else if(loginVerify==1){ 120 | res.put("stateCode", "1"); 121 | }else { 122 | res.put("stateCode", "0"); 123 | } 124 | return res; 125 | } 126 | /** 127 | * 判断用户是否存在 128 | */ 129 | @RequestMapping("/existUsername") 130 | @ResponseBody 131 | public String existUsername(HttpServletRequest request){ 132 | String username=request.getParameter("username"); 133 | boolean isExist=userService.existUsername(username); 134 | if(isExist){ 135 | return "1"; 136 | }else { 137 | return "0"; 138 | } 139 | } 140 | 141 | /** 142 | * 用户登出 143 | */ 144 | @RequestMapping("/signout") 145 | public String signout(HttpSession session){ 146 | session.removeAttribute("userId"); 147 | session.removeAttribute("username"); 148 | return "redirect:/"; 149 | } 150 | /** 151 | * 获取客户端IP 152 | */ 153 | private String getRemortIP(HttpServletRequest request){ 154 | if(request.getHeader("x-forwarded-for")==null){ 155 | return request.getRemoteAddr(); 156 | } 157 | return request.getHeader("x-forwarded-for"); 158 | } 159 | /** 160 | * 用户个人主页 161 | */ 162 | @RequestMapping("/member/{username}") 163 | public ModelAndView personalCenter(@PathVariable("username") String username,HttpSession session){ 164 | boolean ifExistUser=userService.existUsername(username); 165 | //获取统计信息 166 | int topicsNum=topicService.getTopicsNum(); 167 | int usersNum=userService.getUserCount(); 168 | 169 | //获取用户信息 170 | Integer uid= (Integer) session.getAttribute("userId"); 171 | User user=userService.getUserById(uid); 172 | //获取访问量 173 | Integer visitorNum=visitorService.countVisitor(); 174 | //最热主题 175 | List hotestTopics=topicService.listMostCommentsTopics(); 176 | ModelAndView mv=new ModelAndView("user_info"); 177 | mv.addObject("hotestTopics",hotestTopics); 178 | mv.addObject("visitorNum", visitorNum); 179 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 180 | mv.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 181 | if(ifExistUser){ 182 | User resultUser=userService.getUserByUsername(username); 183 | mv.addObject("userInfo",resultUser); 184 | mv.addObject("topicsNum",topicsNum); 185 | mv.addObject("usersNum",usersNum); 186 | mv.addObject("user",user); 187 | return mv; 188 | }else { 189 | String errorInfo="会员未找到"; 190 | mv.addObject("errorInfo", errorInfo); 191 | return mv; 192 | } 193 | } 194 | @RequestMapping("/settings") 195 | public ModelAndView settings(HttpServletRequest request, HttpSession session){ 196 | 197 | Integer uid=(Integer) session.getAttribute("userId"); 198 | User user=userService.getUserById(uid); 199 | 200 | //最热主题 201 | List hotestTopics=topicService.listMostCommentsTopics(); 202 | //获取访问量 203 | Integer visitorNum=visitorService.countVisitor(); 204 | 205 | ModelAndView mv=new ModelAndView("settings"); 206 | mv.addObject("user",user); 207 | mv.addObject("hotestTopics",hotestTopics); 208 | mv.addObject("visitorNum",visitorNum); 209 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 210 | mv.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 211 | return mv; 212 | } 213 | @RequestMapping(value = "/settings/avatar",method = RequestMethod.GET) 214 | public ModelAndView updateAvatar(HttpServletRequest request, HttpSession session){ 215 | 216 | Integer uid=(Integer) session.getAttribute("userId"); 217 | User user=userService.getUserById(uid); 218 | 219 | //最热主题 220 | List hotestTopics=topicService.listMostCommentsTopics(); 221 | //获取访问量 222 | Integer visitorNum=visitorService.countVisitor(); 223 | 224 | ModelAndView mv=new ModelAndView("update_avatar"); 225 | mv.addObject("user",user); 226 | mv.addObject("hotestTopics",hotestTopics); 227 | mv.addObject("visitorNum",visitorNum); 228 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 229 | mv.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 230 | return mv; 231 | } 232 | @RequestMapping(value = "/settings/avatar/update",method = RequestMethod.POST) 233 | public ModelAndView updateAvatarDo(@RequestPart("avatar")MultipartFile avatarFile,HttpServletRequest request,HttpSession session){ 234 | Integer uid= (Integer) session.getAttribute("userId"); 235 | 236 | String fileName=avatarFile.getOriginalFilename(); 237 | String suffix=fileName.substring(fileName.lastIndexOf(".")+1, fileName.length()); 238 | Long date=new Date().getTime(); 239 | String newFileName=date+"-"+uid+"."+suffix; 240 | //绝对路径 241 | String absolutePath=session.getServletContext().getRealPath("/static/img/avatar")+"/"+newFileName; 242 | //相对路径 243 | String relativePath="/img/avatar"+"/"+newFileName; 244 | User newUser=new User(); 245 | newUser.setAvatar(relativePath); 246 | newUser.setId(uid); 247 | File file=new File(absolutePath); 248 | //如果这个文件并不存在 249 | if(!file.exists()){ 250 | try { 251 | avatarFile.transferTo(file); 252 | userService.updateUser(newUser); 253 | }catch (Exception e){ 254 | e.printStackTrace(); 255 | } 256 | } 257 | User user=userService.getUserById(uid); 258 | //最热主题 259 | List hotestTopics=topicService.listMostCommentsTopics(); 260 | //获取访问量 261 | Integer visitorNum=visitorService.countVisitor(); 262 | ModelAndView mv=new ModelAndView("update_avatar"); 263 | mv.addObject("user", user); 264 | mv.addObject("hotestTopics", hotestTopics); 265 | mv.addObject("visitorNum",visitorNum); 266 | mv.addObject("todayVisitor", visitorService.todayVisitor()); 267 | mv.addObject("unreadMessage", messageService.getUnreadMessageNumOfUser(uid)); 268 | return mv; 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /src/main/java/dao/LoginLogMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.LoginLog; 4 | 5 | public interface LoginLogMapper { 6 | LoginLog selectByPrimaryKey(long id); 7 | int deleteByPrimaryKey(int id); 8 | int insert(LoginLog loginLog); 9 | int insertSelective(LoginLog loginLog); 10 | int updateByPrimaryKey(LoginLog loginLog); 11 | int updateByPrimaryKeySelective(LoginLog loginLog); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/dao/MessageMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Message; 4 | 5 | import java.util.List; 6 | 7 | public interface MessageMapper { 8 | int insert(Message message); 9 | List selectAllMessageByUserId(Integer userId); 10 | int readReplyOfTopic(Integer topidId); 11 | List getAllMessage(Integer userId); 12 | int getAllMessageNumOfUser(Integer userId); 13 | int getUnreadMessageNumOfUser(Integer userId); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/dao/ReplyMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Reply; 4 | 5 | import java.util.List; 6 | 7 | public interface ReplyMapper { 8 | int deleteByPrimaryKey(Long id); 9 | int deleteByTopicId(int id); 10 | int insert(Reply reply); 11 | int insertSelective(Reply record);//未实现 12 | Reply selectByPrimaryKey(Long id);//no complete 13 | List getRepliesOfTopic(Integer id); 14 | int updateByPrimaryKeySelective(Reply record);//no 15 | int updateByPrimaryKeyWithBLOBs(Reply record);//no 16 | int updateByPrimaryKey(Reply record); //no 17 | int getRepliesNum(Integer id); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dao/TabMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Tab; 4 | 5 | import java.util.List; 6 | 7 | public interface TabMapper { 8 | int deleteByPrimaryKey(Integer id); 9 | int insert(Tab tab); 10 | int insertSelective(Tab tab); 11 | 12 | Tab selectByPrimaryKey(Integer id);//根据id选择版面 13 | Tab getByTabNameEn(String tabName);//根据名字选择版面 14 | 15 | int updateByPrimaryKeySelective(Tab record); 16 | int updateByPrimaryKey(Tab tab); 17 | 18 | List getAllTabs();//获取全部版面 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dao/TopicMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Topic; 4 | 5 | import java.util.List; 6 | 7 | public interface TopicMapper { 8 | int deleteByPrimaryKey(Integer id); 9 | int insert(Topic topic); 10 | int insertSelective(Topic topic); 11 | //帖子详情 12 | Topic selectById(Integer id); 13 | //一个帖子完整的信息 14 | List listTopicsAndUsers(); 15 | //根据tab页查询topic 16 | List listTopicsAndUsersOfTab(Integer tabId); 17 | //热门帖子 18 | List listMostCommentsTopics(); 19 | int updateByPrimaryKeySelective(Topic topic); 20 | //更新内容 21 | int updateByPrimaryKeyWithBLOBs(Topic topic); 22 | //更新其他 23 | int updateByPrimaryKey(Topic topic); 24 | List getAllTopics(); 25 | //增加访问流量 26 | int clickAddOne(Integer id); 27 | //获取主题总数 28 | int getTopicsNum(); 29 | //获取活跃主题 30 | List listActiveTopics(Integer tabiId); 31 | //获取全部活跃主题 32 | List listAllActiveTopics(); 33 | //获取最近主题 34 | List listRecentTopics(Integer tabId); 35 | //获取全部最近主题 36 | List listAllRecentTopics(); 37 | //获取全部精品帖子 38 | List listAllEssenceTopics(); 39 | //获取部分精品帖子 40 | List listEssenceTopics(Integer tabId); 41 | //删除主题 42 | int deleteByPrimaryKey(int topicId); 43 | //查看是否帖子存在 44 | int existTopic(Integer topicId); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import org.apache.ibatis.annotations.Param; 4 | import pojo.User; 5 | 6 | public interface UserMapper { 7 | User selectByPrimaryKey(Integer id); 8 | //查询用户数 9 | int getUserCount(); 10 | User selectByUsername(String username); 11 | //查询username是否存在 12 | int existUsername(String username); 13 | int deleteByPrimaryKey(Integer id); 14 | int addUser(User user); 15 | int insertSelective(User user); 16 | int updateByPrimaryKeySelective(User user); 17 | int updateByPrimaryKey(User user); 18 | int addCredit(@Param("points")Integer points,@Param("id")Integer id);//增加积分 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dao/VisitorMapper.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import pojo.Visitor; 4 | 5 | public interface VisitorMapper { 6 | int insert(Visitor visitor); 7 | int countVisitor(); 8 | int todayVisitor(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/intercepter/CORSFilter.java: -------------------------------------------------------------------------------- 1 | package intercepter; 2 | 3 | import javax.servlet.*; 4 | import javax.servlet.http.HttpServletResponse; 5 | import java.io.IOException; 6 | 7 | public class CORSFilter implements Filter { 8 | public void init(FilterConfig filterConfig) throws ServletException { 9 | 10 | } 11 | 12 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { 13 | HttpServletResponse response= (HttpServletResponse) servletResponse; 14 | response.addHeader("Access-Control-Allow-Origin", "*"); 15 | response.addHeader("Access-Control-Allow-Methods", "GET,POST,PATCH,PUT,OPTIONS"); 16 | chain.doFilter(servletRequest,response); 17 | } 18 | 19 | public void destroy() { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/mapper/LoginLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | id,user_id,login_time,ip,device 13 | 14 | 15 | 21 | 22 | delete from login_log 23 | where id=#{id,jdbcType=BIGINT} 24 | 25 | 26 | insert into login_log (user_id, login_time, 27 | ip, device) 28 | values (#{userId,jdbcType=INTEGER}, #{loginTime,jdbcType=TIMESTAMP}, 29 | #{ip,jdbcType=VARCHAR}, #{device,jdbcType=VARCHAR}) 30 | 31 | 32 | insert into login_log 33 | 34 | 35 | id, 36 | 37 | 38 | user_id, 39 | 40 | 41 | login_time, 42 | 43 | 44 | ip, 45 | 46 | 47 | device, 48 | 49 | 50 | 51 | 52 | #{id,jdbcType=BIGINT}, 53 | 54 | 55 | #{userId,jdbcType=INTEGER}, 56 | 57 | 58 | #{loginTime,jdbcType=TIMESTAMP}, 59 | 60 | 61 | #{ip,jdbcType=VARCHAR}, 62 | 63 | 64 | #{device,jdbcType=VARCHAR}, 65 | 66 | 67 | 68 | 69 | update login_log 70 | set user_id=#{userId,jdbcType=INTEGER}, 71 | login_time = #{loginTime,jdbcType=TIMESTAMP}, 72 | ip = #{ip,jdbcType=VARCHAR}, 73 | device = #{device,jdbcType=VARCHAR} 74 | where id=#{id,jdbcType=BIGINT} 75 | 76 | 77 | update login_log 78 | 79 | 80 | user_id = #{userId,jdbcType=INTEGER}, 81 | 82 | 83 | login_time = #{loginTime,jdbcType=TIMESTAMP}, 84 | 85 | 86 | ip = #{ip,jdbcType=VARCHAR}, 87 | 88 | 89 | device = #{device,jdbcType=VARCHAR}, 90 | 91 | 92 | where id = #{id,jdbcType=BIGINT} 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/main/java/mapper/MessageMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | insert into message (context,type,topic_id,sender_id,action,is_read,user_id,create_time,reply_id) 18 | values (#{context,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{topic_id,jdbcType=INTEGER}, 19 | #{sender_id,jdbcType=INTEGER},#{action,jdbcType=VARCHAR},#{is_read,jdbcType=INTEGER},#{user_id,jdbcType=INTEGER}, 20 | #{create_time,jdbcType=TIMESTAMP},#{reply_id,jdbcType=BIGINT}) 21 | 22 | 25 | 28 | 31 | 35 | 36 | update message 37 | set is_read=1 38 | where topic_id=#{id,jdbcType=INTEGER} 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/mapper/ReplyMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 30 | 31 | delete from reply 32 | where id=#{id,jdbcType=BIGINT} 33 | 34 | 35 | insert into reply (topic_id, reply_user_id, 36 | create_time, update_time, 37 | content) 38 | values (#{topicId,jdbcType=INTEGER}, #{replyUserId,jdbcType=INTEGER}, 39 | #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, 40 | #{content,jdbcType=LONGVARCHAR}) 41 | 42 | 43 | 44 | delete from reply 45 | where topic_id=#{id,jdbcType=INTEGER} 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/mapper/TabMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | id,tab_name,tab_name_en 11 | 12 | 15 | 16 | 22 | 23 | 29 | 30 | 31 | delete from tab 32 | where id=#{id,jdbcType=INTEGER} 33 | 34 | 35 | insert into tab (id,tab_name) 36 | values (#{id,jdbcType=INTEGER},#{tabName,jdbcType=INTEGER}) 37 | 38 | 39 | insert into tab 40 | 41 | 42 | id, 43 | 44 | 45 | tab_name, 46 | 47 | 48 | 49 | 50 | #{id,jdbcType=INTEGER}, 51 | 52 | 53 | #{tabName,jdbcType=INTEGER}, 54 | 55 | 56 | 57 | 58 | update tab 59 | 60 | 61 | tab_name = #{tabName,jdbcType=INTEGER}, 62 | 63 | 64 | where id = #{id,jdbcType=INTEGER} 65 | 66 | 67 | update tab 68 | set tab_name=#{tabName,jdbcType=VARCHAR} 69 | where id=#{id,jdbcType=INTEGER} 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/mapper/TopicMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | id,user_id,create_time,update_time,title,click,tab_id,isEssence 66 | 67 | 68 | content 69 | 70 | 78 | 88 | 93 | 94 | 100 | 105 | 113 | 114 | 124 | 135 | 136 | 146 | 147 | 158 | 159 | 170 | 181 | 184 | 185 | insert into topic(user_id, create_time, 186 | update_time, title, 187 | tab_id, content,isEssence) 188 | values ( #{userId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 189 | #{updateTime,jdbcType=TIMESTAMP}, #{title,jdbcType=VARCHAR}, 190 | #{tabId,jdbcType=TINYINT}, #{content,jdbcType=LONGVARCHAR},0) 191 | 192 | 193 | 194 | insert into topic 195 | 196 | 197 | id, 198 | 199 | 200 | user_id, 201 | 202 | 203 | create_time, 204 | 205 | 206 | update_time, 207 | 208 | 209 | title, 210 | 211 | 212 | click, 213 | 214 | 215 | tab_id, 216 | 217 | 218 | content, 219 | 220 | 221 | 222 | 223 | #{id,jdbcType=INTEGER}, 224 | 225 | 226 | #{userId,jdbcType=INTEGER}, 227 | 228 | 229 | #{createTime,jdbcType=TIMESTAMP}, 230 | 231 | 232 | #{updateTime,jdbcType=TIMESTAMP}, 233 | 234 | 235 | #{title,jdbcType=VARCHAR}, 236 | 237 | 238 | #{click,jdbcType=INTEGER}, 239 | 240 | 241 | #{tabId,jdbcType=TINYINT}, 242 | 243 | 244 | #{content,jdbcType=LONGVARCHAR}, 245 | 246 | 247 | 248 | 249 | update topic 250 | 251 | 252 | user_id = #{userId,jdbcType=INTEGER}, 253 | 254 | 255 | create_time = #{createTime,jdbcType=TIMESTAMP}, 256 | 257 | 258 | update_time = #{updateTime,jdbcType=TIMESTAMP}, 259 | 260 | 261 | title = #{title,jdbcType=VARCHAR}, 262 | 263 | 264 | click = #{click,jdbcType=INTEGER}, 265 | 266 | 267 | tab_id = #{tabId,jdbcType=TINYINT}, 268 | 269 | 270 | isEssence = #{isEssence,jdbcType=INTEGER}, 271 | 272 | 273 | content = #{content,jdbcType=LONGVARCHAR}, 274 | 275 | 276 | where id=#{id,jdbcType=INTEGER} 277 | 278 | 279 | update topic 280 | set user_id = #{userId,jdbcType=INTEGER}, 281 | create_time = #{createTime,jdbcType=TIMESTAMP}, 282 | update_time = #{updateTime,jdbcType=TIMESTAMP}, 283 | title = #{title,jdbcType=VARCHAR}, 284 | click = #{click,jdbcType=INTEGER}, 285 | tab_id = #{tabId,jdbcType=TINYINT}, 286 | content = #{content,jdbcType=LONGVARCHAR} 287 | where id = #{id,jdbcType=INTEGER} 288 | 289 | 290 | update topic 291 | set user_id = #{userId,jdbcType=INTEGER}, 292 | create_time = #{createTime,jdbcType=TIMESTAMP}, 293 | update_time = #{updateTime,jdbcType=TIMESTAMP}, 294 | title = #{title,jdbcType=VARCHAR}, 295 | click = #{click,jdbcType=INTEGER}, 296 | tab_id = #{tabId,jdbcType=TINYINT}, 297 | isEssence = #{isEssence,jdbcType=INTEGER} 298 | where id = #{id,jdbcType=INTEGER} 299 | 300 | 301 | update topic 302 | set click=click+1 303 | where id=#{id,jdbcType=INTEGER} 304 | 305 | 306 | 307 | delete from topic 308 | where id=#{id,jdbcType=INTEGER} 309 | 310 | -------------------------------------------------------------------------------- /src/main/java/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id,username,password,email,phone_num,create_time,update_time,credit,avatar,type 18 | 19 | 25 | 26 | 31 | 37 | 40 | 41 | 42 | delete from user 43 | where id=#{id,jdbcType=INTEGER} 44 | 45 | 46 | 47 | insert into user (username,password,email,phone_num,create_time,update_time,credit,type,avatar) 48 | values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, 49 | #{email,jdbcType=VARCHAR}, #{phoneNum,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 50 | #{updateTime,jdbcType=TIMESTAMP}, #{credit,jdbcType=INTEGER}, 51 | #{type,jdbcType=TINYINT},#{avatar,jdbcType=VARCHAR}) 52 | 53 | 54 | insert into user 55 | 56 | 57 | id, 58 | 59 | 60 | username, 61 | 62 | 63 | password, 64 | 65 | 66 | email, 67 | 68 | 69 | phone_num, 70 | 71 | 72 | create_time, 73 | 74 | 75 | update_time, 76 | 77 | 78 | credit, 79 | 80 | 81 | avatar, 82 | 83 | 84 | type, 85 | 86 | 87 | 88 | 89 | #{id,jdbcType=INTEGER}, 90 | 91 | 92 | #{username,jdbcType=VARCHAR}, 93 | 94 | 95 | #{password,jdbcType=VARCHAR}, 96 | 97 | 98 | #{email,jdbcType=VARCHAR}, 99 | 100 | 101 | #{phoneNum,jdbcType=VARCHAR}, 102 | 103 | 104 | #{createTime,jdbcType=TIMESTAMP}, 105 | 106 | 107 | #{updateTime,jdbcType=TIMESTAMP}, 108 | 109 | 110 | #{credit,jdbcType=INTEGER}, 111 | 112 | 113 | #{avatar,jdbcType=VARCHAR}, 114 | 115 | 116 | #{type,jdbcType=TINYINT}, 117 | 118 | 119 | 120 | 121 | update user 122 | 123 | 124 | username = #{username,jdbcType=VARCHAR}, 125 | 126 | 127 | password = #{password,jdbcType=VARCHAR}, 128 | 129 | 130 | email = #{email,jdbcType=VARCHAR}, 131 | 132 | 133 | phone_num = #{phoneNum,jdbcType=VARCHAR}, 134 | 135 | 136 | create_time = #{createTime,jdbcType=TIMESTAMP}, 137 | 138 | 139 | update_time = #{updateTime,jdbcType=TIMESTAMP}, 140 | 141 | 142 | credit = #{credit,jdbcType=INTEGER}, 143 | 144 | 145 | avatar = #{avatar,jdbcType=VARCHAR}, 146 | 147 | 148 | type = #{type,jdbcType=TINYINT}, 149 | 150 | 151 | where id = #{id,jdbcType=INTEGER} 152 | 153 | 154 | update user 155 | set username = #{username,jdbcType=VARCHAR}, 156 | password = #{password,jdbcType=VARCHAR}, 157 | email = #{email,jdbcType=VARCHAR}, 158 | phone_num = #{phoneNum,jdbcType=VARCHAR}, 159 | create_time = #{createTime,jdbcType=TIMESTAMP}, 160 | update_time = #{updateTime,jdbcType=TIMESTAMP}, 161 | credit = #{credit,jdbcType=INTEGER}, 162 | avatar = #{avatar,jdbcType=VARCHAR}, 163 | type = #{type,jdbcType=TINYINT} 164 | where id = #{id,jdbcType=INTEGER} 165 | 166 | 167 | update user set credit=credit+#{points,jdbcType=INTEGER} where id=#{id,jdbcType=INTEGER} 168 | 169 | -------------------------------------------------------------------------------- /src/main/java/mapper/VisitorMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | insert into visitor (IP,visit_time,device) 12 | values (#{IP,jdbcType=VARCHAR},#{visitTime,jdbcType=TIMESTAMP},#{device,jdbcType=VARCHAR}) 13 | 14 | 17 | 20 | -------------------------------------------------------------------------------- /src/main/java/pojo/LoginLog.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 登录日志 7 | */ 8 | public class LoginLog { 9 | private Long id; 10 | 11 | private Integer userId; 12 | 13 | private Date loginTime; 14 | 15 | private String ip; 16 | 17 | private String device; 18 | 19 | public Long getId() { 20 | return id; 21 | } 22 | 23 | public void setId(Long id) { 24 | this.id = id; 25 | } 26 | 27 | public Integer getUserId() { 28 | return userId; 29 | } 30 | 31 | public void setUserId(Integer userId) { 32 | this.userId = userId; 33 | } 34 | 35 | public Date getLoginTime() { 36 | return loginTime; 37 | } 38 | 39 | public void setLoginTime(Date loginTime) { 40 | this.loginTime = loginTime; 41 | } 42 | 43 | public String getIp() { 44 | return ip; 45 | } 46 | 47 | public void setIp(String ip) { 48 | this.ip = ip; 49 | } 50 | 51 | public String getDevice() { 52 | return device; 53 | } 54 | 55 | public void setDevice(String device) { 56 | this.device = device; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/pojo/Message.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.Date; 4 | 5 | public class Message { 6 | private Integer id; 7 | private String context;// 消息的内容 8 | private String type;//消息类型 0 回复 1关注 2点赞 9 | private Integer topic_id;//对应的主题id 10 | private Integer sender_id;//发送消息者id; 11 | private String action;//动作类型,如点赞 12 | private Integer is_read;//阅读状态 0 未阅读 1 已阅读 13 | private Integer user_id;//接受消息的id 14 | private Date create_time;//创建这条消息的时间 15 | private Long reply_id;//回复的id 16 | private User sender; 17 | private String topic_name;//主题名字 18 | 19 | public String getTopic_name() { 20 | return topic_name; 21 | } 22 | 23 | public void setTopic_name(String topic_name) { 24 | this.topic_name = topic_name; 25 | } 26 | 27 | public User getSender() { 28 | return sender; 29 | } 30 | 31 | public void setSender(User sender) { 32 | this.sender = sender; 33 | } 34 | 35 | public Long getReply_id() { 36 | return reply_id; 37 | } 38 | 39 | public void setReply_id(Long reply_id) { 40 | this.reply_id = reply_id; 41 | } 42 | 43 | public Integer getId() { 44 | return id; 45 | } 46 | 47 | public void setId(Integer id) { 48 | this.id = id; 49 | } 50 | 51 | public String getContext() { 52 | return context; 53 | } 54 | 55 | public void setContext(String context) { 56 | this.context = context; 57 | } 58 | 59 | public String getType() { 60 | return type; 61 | } 62 | 63 | public void setType(String type) { 64 | this.type = type; 65 | } 66 | 67 | public Integer getTopic_id() { 68 | return topic_id; 69 | } 70 | 71 | public void setTopic_id(Integer topic_id) { 72 | this.topic_id = topic_id; 73 | } 74 | 75 | public Integer getSender_id() { 76 | return sender_id; 77 | } 78 | 79 | public void setSender_id(Integer sender_id) { 80 | this.sender_id = sender_id; 81 | } 82 | 83 | public String getAction() { 84 | return action; 85 | } 86 | 87 | public void setAction(String action) { 88 | this.action = action; 89 | } 90 | 91 | public Integer getIs_read() { 92 | return is_read; 93 | } 94 | 95 | public void setIs_read(Integer is_read) { 96 | this.is_read = is_read; 97 | } 98 | 99 | public Integer getUser_id() { 100 | return user_id; 101 | } 102 | 103 | public void setUser_id(Integer user_id) { 104 | this.user_id = user_id; 105 | } 106 | 107 | public Date getCreate_time() { 108 | return create_time; 109 | } 110 | 111 | public void setCreate_time(Date create_time) { 112 | this.create_time = create_time; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/pojo/Reply.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | public class Reply { 7 | private User user; 8 | 9 | private Long id; 10 | 11 | private Integer topicId; 12 | 13 | private Integer replyUserId; 14 | 15 | private Date createTime; 16 | 17 | private Date updateTime; 18 | 19 | private String device; 20 | 21 | private String content; 22 | 23 | 24 | 25 | public void setUser(User user) { 26 | this.user = user; 27 | } 28 | 29 | public User getUser() { 30 | return user; 31 | } 32 | 33 | public Long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(Long id) { 38 | this.id = id; 39 | } 40 | 41 | public Integer getTopicId() { 42 | return topicId; 43 | } 44 | 45 | public void setTopicId(Integer topicId) { 46 | this.topicId = topicId; 47 | } 48 | 49 | public Integer getReplyUserId() { 50 | return replyUserId; 51 | } 52 | 53 | public void setReplyUserId(Integer replyUserId) { 54 | this.replyUserId = replyUserId; 55 | } 56 | 57 | public Date getCreateTime() { 58 | return createTime; 59 | } 60 | 61 | public void setCreateTime(Date createTime) { 62 | this.createTime = createTime; 63 | } 64 | 65 | public Date getUpdateTime() { 66 | return updateTime; 67 | } 68 | 69 | public void setUpdateTime(Date updateTime) { 70 | this.updateTime = updateTime; 71 | } 72 | 73 | public String getDevice() { 74 | return device; 75 | } 76 | 77 | public void setDevice(String device) { 78 | this.device = device == null ? null : device.trim(); 79 | } 80 | 81 | public String getContent() { 82 | return content; 83 | } 84 | 85 | public void setContent(String content) { 86 | this.content = content == null ? null : content.trim(); 87 | } 88 | 89 | public String getLocalCreateTime() { 90 | SimpleDateFormat df = new SimpleDateFormat("yyyy-M-dd HH:mm:ss");//设置日期格式 91 | String date = df.format(this.createTime); 92 | return date; 93 | } 94 | public String getLocalUpdateTime() { 95 | SimpleDateFormat df = new SimpleDateFormat("yyyy-M-dd HH:mm:ss");//设置日期格式 96 | String date = df.format(updateTime); 97 | return date; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/pojo/Tab.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.List; 4 | 5 | public class Tab { 6 | private Integer id; 7 | 8 | private String tabName; 9 | 10 | private String tabNameEn; 11 | 12 | private List topics; 13 | 14 | public String getTabNameEn() { 15 | return tabNameEn; 16 | } 17 | 18 | public void setTabNameEn(String tabNameEn) { 19 | this.tabNameEn = tabNameEn; 20 | } 21 | 22 | 23 | 24 | public void setTopics(List topics) { 25 | this.topics = topics; 26 | } 27 | 28 | public List getTopics() { 29 | return topics; 30 | } 31 | 32 | public Integer getId() { 33 | return id; 34 | } 35 | 36 | public void setId(Integer id) { 37 | this.id = id; 38 | } 39 | 40 | public String getTabName() { 41 | return tabName; 42 | } 43 | 44 | public void setTabName(String tabName) { 45 | this.tabName = tabName; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/pojo/Topic.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | /** 7 | * 主题 8 | */ 9 | public class Topic { 10 | private User user; 11 | private Tab tab; 12 | private Integer countReplies;//回复数 13 | private Integer id; 14 | private Integer userId; 15 | private Date createTime; 16 | private Date updateTime; 17 | private String title; 18 | private Integer click; 19 | private Byte tabId; 20 | private String content; 21 | private Integer isEssence; 22 | 23 | public Integer getIsEssence() { 24 | return isEssence; 25 | } 26 | 27 | public void setIsEssence(Integer isEssence) { 28 | this.isEssence = isEssence; 29 | } 30 | 31 | public User getUser() { 32 | return user; 33 | } 34 | 35 | public void setUser(User user) { 36 | this.user = user; 37 | } 38 | 39 | public Tab getTab() { 40 | return tab; 41 | } 42 | 43 | public void setTab(Tab tab) { 44 | this.tab = tab; 45 | } 46 | 47 | public Integer getCountReplies() { 48 | return countReplies; 49 | } 50 | 51 | public void setCountReplies(Integer countReplies) { 52 | this.countReplies = countReplies; 53 | } 54 | 55 | public Integer getId() { 56 | return id; 57 | } 58 | 59 | public void setId(Integer id) { 60 | this.id = id; 61 | } 62 | 63 | public Integer getUserId() { 64 | return userId; 65 | } 66 | 67 | public void setUserId(Integer userId) { 68 | this.userId = userId; 69 | } 70 | 71 | public Date getCreateTime() { 72 | return createTime; 73 | } 74 | 75 | public void setCreateTime(Date createTime) { 76 | this.createTime = createTime; 77 | } 78 | 79 | public Date getUpdateTime() { 80 | return updateTime; 81 | } 82 | 83 | public void setUpdateTime(Date updateTime) { 84 | this.updateTime = updateTime; 85 | } 86 | 87 | public String getTitle() { 88 | return title; 89 | } 90 | 91 | public void setTitle(String title) { 92 | this.title = title; 93 | } 94 | 95 | public Integer getClick() { 96 | return click; 97 | } 98 | 99 | public void setClick(Integer click) { 100 | this.click = click; 101 | } 102 | 103 | public Byte getTabId() { 104 | return tabId; 105 | } 106 | 107 | public void setTabId(Byte tabId) { 108 | this.tabId = tabId; 109 | } 110 | 111 | public String getContent() { 112 | return content; 113 | } 114 | 115 | public void setContent(String content) { 116 | this.content = content; 117 | } 118 | 119 | /** 120 | * Date日期转字符串 121 | */ 122 | public String getLocalCreateTime(){ 123 | if(createTime==null){ 124 | return null; 125 | } 126 | //设置日期格式 127 | SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 128 | return df.format(createTime); 129 | } 130 | public String getLocalUpdateTime(){ 131 | if(updateTime==null){ 132 | return null; 133 | } 134 | SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 135 | return df.format(updateTime); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/main/java/pojo/User.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | public class User { 7 | private Integer id; 8 | 9 | private String username; 10 | 11 | private String password; 12 | 13 | private String email; 14 | 15 | private String phoneNum; 16 | 17 | private Date createTime; 18 | 19 | private Date updateTime; 20 | 21 | private Integer credit; 22 | 23 | private String avatar; 24 | 25 | private Byte type; 26 | 27 | 28 | public Integer getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) { 33 | this.id = id; 34 | } 35 | 36 | public String getUsername() { 37 | return username; 38 | } 39 | 40 | public void setUsername(String username) { 41 | this.username = username == null ? null : username.trim(); 42 | } 43 | 44 | public String getPassword() { 45 | return password; 46 | } 47 | 48 | public void setPassword(String password) { 49 | this.password = password == null ? null : password.trim(); 50 | } 51 | 52 | public String getEmail() { 53 | return email; 54 | } 55 | 56 | public void setEmail(String email) { 57 | this.email = email == null ? null : email.trim(); 58 | } 59 | 60 | public String getPhoneNum() { 61 | return phoneNum; 62 | } 63 | 64 | public void setPhoneNum(String phoneNum) { 65 | this.phoneNum = phoneNum == null ? null : phoneNum.trim(); 66 | } 67 | 68 | public Date getCreateTime() { 69 | return createTime; 70 | } 71 | 72 | public void setCreateTime(Date createTime) { 73 | this.createTime = createTime; 74 | } 75 | 76 | public Date getUpdateTime() { 77 | return updateTime; 78 | } 79 | 80 | public void setUpdateTime(Date updateTime) { 81 | this.updateTime = updateTime; 82 | } 83 | 84 | public Integer getCredit() { 85 | return credit; 86 | } 87 | 88 | public void setCredit(Integer credit) { 89 | this.credit = credit; 90 | } 91 | 92 | public String getAvatar() { 93 | return avatar; 94 | } 95 | 96 | public void setAvatar(String avatar) { 97 | this.avatar = avatar == null ? null : avatar.trim(); 98 | } 99 | 100 | public Byte getType() { 101 | return type; 102 | } 103 | 104 | public void setType(Byte type) { 105 | this.type = type; 106 | } 107 | 108 | public String getLocalCreateTime() { 109 | SimpleDateFormat df = new SimpleDateFormat("yyyy-M-dd HH:mm");//设置日期格式 110 | String date = df.format(this.createTime); 111 | return date; 112 | } 113 | public String getLocalUpdateTime() { 114 | SimpleDateFormat df = new SimpleDateFormat("yyyy-M-dd HH:mm");//设置日期格式 115 | String date = df.format(updateTime); 116 | return date; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/pojo/Visitor.java: -------------------------------------------------------------------------------- 1 | package pojo; 2 | 3 | import java.util.Date; 4 | 5 | public class Visitor { 6 | private Integer id; 7 | private String IP; 8 | private Date visitTime; 9 | private String device; 10 | 11 | public void setId(Integer id) { 12 | this.id = id; 13 | } 14 | 15 | public Integer getId() { 16 | return id; 17 | } 18 | 19 | public String getIP() { 20 | return IP; 21 | } 22 | 23 | public void setIP(String IP) { 24 | this.IP = IP; 25 | } 26 | 27 | public Date getVisitTime() { 28 | return visitTime; 29 | } 30 | 31 | public void setVisitTime(Date visitTime) { 32 | this.visitTime = visitTime; 33 | } 34 | 35 | public String getDevice() { 36 | return device; 37 | } 38 | 39 | public void setDevice(String device) { 40 | this.device = device; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/LoginLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import dao.LoginLogMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.LoginLog; 7 | import service.LoginLogService; 8 | @Service 9 | public class LoginLogServiceImpl implements LoginLogService { 10 | @Autowired 11 | LoginLogMapper loginLogMapper; 12 | public boolean addLoginLog(LoginLog loginLog) { 13 | int result=loginLogMapper.insert(loginLog); 14 | if(result>0){ 15 | return true; 16 | }else { 17 | return false; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/MessageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import dao.MessageMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.Message; 7 | import service.MessageService; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class MessageServiceImpl implements MessageService { 13 | @Autowired 14 | MessageMapper messageMapper; 15 | public boolean insert(Message message) { 16 | return messageMapper.insert(message)>0; 17 | } 18 | 19 | public List selectAllMessageByUserId(Integer userId) { 20 | return messageMapper.selectAllMessageByUserId(userId); 21 | } 22 | 23 | public boolean readReplyOfTopic(Integer topidId) { 24 | return messageMapper.readReplyOfTopic(topidId)>0; 25 | } 26 | 27 | public List getAllMessage(Integer userId) { 28 | return messageMapper.getAllMessage(userId); 29 | } 30 | 31 | public int getAllMessageNumOfUser(Integer userId) { 32 | return messageMapper.getAllMessageNumOfUser(userId); 33 | } 34 | 35 | public int getUnreadMessageNumOfUser(Integer userId) { 36 | return messageMapper.getUnreadMessageNumOfUser(userId); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/ReplyServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import dao.ReplyMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.Reply; 7 | import service.ReplyService; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class ReplyServiceImpl implements ReplyService { 13 | @Autowired 14 | ReplyMapper replyMapper; 15 | 16 | public List getRepliesOfTopic(Integer topidId) { 17 | return replyMapper.getRepliesOfTopic(topidId); 18 | } 19 | 20 | public boolean addReply(Reply reply) { 21 | return replyMapper.insert(reply)>0; 22 | } 23 | 24 | public int repliesNum(Integer topicId) { 25 | return replyMapper.getRepliesNum(topicId); 26 | } 27 | 28 | public int deleteByTopicId(int id) { 29 | return replyMapper.deleteByTopicId(id); 30 | } 31 | 32 | public int deleteByPrimaryKey(Long id) { 33 | return replyMapper.deleteByPrimaryKey(id); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/TabServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import dao.TabMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.Tab; 7 | import service.TabService; 8 | 9 | import java.util.List; 10 | @Service 11 | public class TabServiceImpl implements TabService { 12 | @Autowired 13 | TabMapper tabMapper; 14 | //获取全部版面 15 | public List getAllTabs() { 16 | return tabMapper.getAllTabs(); 17 | } 18 | //根据名字选择版面 19 | public Tab getByTabNameEn(String tabName) { 20 | return tabMapper.getByTabNameEn(tabName); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/TopicServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import dao.TopicMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import pojo.Topic; 8 | import service.TopicService; 9 | 10 | import java.util.List; 11 | @Service 12 | public class TopicServiceImpl implements TopicService { 13 | @Autowired 14 | public TopicMapper topicMapper; 15 | //获取全部主题 16 | public List getAllTopics() { 17 | return topicMapper.getAllTopics(); 18 | } 19 | 20 | public List listTopicsAndUsers() { 21 | return topicMapper.listTopicsAndUsers(); 22 | } 23 | 24 | public List listMostCommentsTopics() { 25 | return topicMapper.listMostCommentsTopics(); 26 | } 27 | 28 | public List listTopicsAndUsersOfTab(Integer tabId) { 29 | return topicMapper.listTopicsAndUsersOfTab(tabId); 30 | } 31 | //获取指定id主题 32 | public Topic selectById(Integer id) { 33 | Topic topic=topicMapper.selectById(id); 34 | return topic; 35 | } 36 | 37 | public boolean addTopic(Topic topic) { 38 | return topicMapper.insert(topic)>0; 39 | } 40 | 41 | public boolean clickAddOne(Integer id) { 42 | return topicMapper.clickAddOne(id)>0; 43 | } 44 | 45 | public int getTopicsNum() { 46 | return topicMapper.getTopicsNum(); 47 | } 48 | 49 | public List listActiveTopics(Integer tabId) { 50 | return topicMapper.listActiveTopics(tabId); 51 | } 52 | 53 | public List listAllActiveTopics() { 54 | return topicMapper.listAllActiveTopics(); 55 | } 56 | 57 | public List listRecentTopics(Integer tabId) { 58 | return topicMapper.listRecentTopics(tabId); 59 | } 60 | 61 | public List listAllRecentTopics() { 62 | return topicMapper.listAllRecentTopics(); 63 | } 64 | 65 | public int updateByPrimaryKeySelective(Topic topic) { 66 | return topicMapper.updateByPrimaryKeySelective(topic); 67 | } 68 | 69 | public List listAllEssenceTopics() { 70 | return topicMapper.listAllEssenceTopics(); 71 | } 72 | 73 | public List listEssenceTopics(Integer tabId) { 74 | return topicMapper.listEssenceTopics(tabId); 75 | } 76 | 77 | public int deleteByPrimaryKey(int topicId) { 78 | return topicMapper.deleteByPrimaryKey(topicId); 79 | } 80 | 81 | public boolean existTopic(Integer topicId) { 82 | return topicMapper.existTopic(topicId)>0; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import dao.UserMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.User; 7 | import service.UserService; 8 | 9 | @Service 10 | public class UserServiceImpl implements UserService { 11 | @Autowired 12 | UserMapper userMapper; 13 | 14 | public boolean addUser(User user) { 15 | return userMapper.addUser(user)>0; 16 | } 17 | //登陆检查 18 | public int login(String username, String password) { 19 | //判断username是否存在 20 | boolean existUsername=existUsername(username); 21 | //如果存在,验证密码 22 | if(existUsername){ 23 | User user=userMapper.selectByUsername(username); 24 | if(user.getPassword().equals(password)){ 25 | return 2; 26 | } 27 | return 1; 28 | } 29 | return 0; 30 | } 31 | 32 | public boolean addCredit(Integer points, Integer id) { 33 | return userMapper.addCredit(points,id)>0; 34 | } 35 | 36 | public boolean existUsername(String username) { 37 | return userMapper.existUsername(username)==1; 38 | } 39 | 40 | public User getUserByUsername(String username) { 41 | User user=userMapper.selectByUsername(username); 42 | return user; 43 | } 44 | 45 | public int getUserCount() { 46 | return userMapper.getUserCount(); 47 | } 48 | 49 | public boolean updateUser(User user) { 50 | return userMapper.updateByPrimaryKeySelective(user)>0; 51 | } 52 | 53 | public User getUserById(Integer id) { 54 | return userMapper.selectByPrimaryKey(id); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/service/Impl/VisitorServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.Impl; 2 | 3 | import dao.VisitorMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.Visitor; 7 | import service.VisitorService; 8 | 9 | @Service 10 | public class VisitorServiceImpl implements VisitorService { 11 | @Autowired 12 | VisitorMapper visitorMapper; 13 | public boolean insert(Visitor visitor) { 14 | return visitorMapper.insert(visitor)>0; 15 | } 16 | 17 | public int countVisitor() { 18 | return visitorMapper.countVisitor(); 19 | } 20 | 21 | public int todayVisitor() { 22 | return visitorMapper.todayVisitor(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/service/LoginLogService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.LoginLog; 4 | 5 | public interface LoginLogService { 6 | //插入一条登陆日志 7 | boolean addLoginLog(LoginLog loginLog); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/service/MessageService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Message; 4 | 5 | import java.util.List; 6 | 7 | public interface MessageService { 8 | boolean insert(Message message); 9 | List selectAllMessageByUserId(Integer userId); 10 | boolean readReplyOfTopic(Integer topidId); 11 | List getAllMessage(Integer userId); 12 | int getAllMessageNumOfUser(Integer userId); 13 | int getUnreadMessageNumOfUser(Integer userId); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/service/ReplyService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Reply; 4 | 5 | import java.util.List; 6 | 7 | public interface ReplyService { 8 | List getRepliesOfTopic(Integer topidId); 9 | boolean addReply(Reply reply); 10 | int repliesNum(Integer topicId); 11 | //删除某个主题下面的回复 12 | int deleteByTopicId(int id); 13 | //删除某个回复 14 | int deleteByPrimaryKey(Long id); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/service/TabService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Tab; 4 | 5 | import java.util.List; 6 | 7 | public interface TabService { 8 | List getAllTabs(); 9 | Tab getByTabNameEn(String tabName); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/service/TopicService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Topic; 4 | 5 | import java.util.List; 6 | 7 | public interface TopicService { 8 | //获取全部主题 9 | List getAllTopics(); 10 | //获取全部主题及用户信息 用于首页 11 | List listTopicsAndUsers(); 12 | //获取最多评论主题列表 13 | List listMostCommentsTopics(); 14 | //获取某个板块下的主题及用户信息 用于渲染板块页面 15 | List listTopicsAndUsersOfTab(Integer tabId); 16 | //获取指定ID主题 17 | Topic selectById(Integer id); 18 | //新建主题 19 | boolean addTopic(Topic topic); 20 | //点击量加一 21 | boolean clickAddOne(Integer id); 22 | //获取主题总数 23 | int getTopicsNum(); 24 | //获取活跃主题 25 | List listActiveTopics(Integer tabId); 26 | //获取全部活跃主题 27 | List listAllActiveTopics(); 28 | //获取最近主题 29 | List listRecentTopics(Integer tabId); 30 | //获取全部最近主题 31 | List listAllRecentTopics(); 32 | //更新帖子 33 | int updateByPrimaryKeySelective(Topic topic); 34 | //获取全部精品帖子 35 | List listAllEssenceTopics(); 36 | //获取部分精品帖子 37 | List listEssenceTopics(Integer tabId); 38 | //删除主题 39 | int deleteByPrimaryKey(int topicId); 40 | //查看是否帖子存在 41 | boolean existTopic(Integer topicId); 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/service/UserService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.User; 4 | 5 | public interface UserService { 6 | /* 7 | 用户注册 8 | */ 9 | boolean addUser(User user); 10 | /* 11 | 登陆验证 12 | */ 13 | int login(String username,String password); 14 | /* 15 | * 添加积分 16 | */ 17 | boolean addCredit(Integer points,Integer id); 18 | /* 19 | 检查username是否存在 20 | */ 21 | boolean existUsername(String username); 22 | /* 23 | 获取用户信息 24 | */ 25 | User getUserByUsername(String username); 26 | /* 27 | 获取用户数 28 | */ 29 | int getUserCount(); 30 | boolean updateUser(User user); 31 | User getUserById(Integer id); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/service/VisitorService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import pojo.Visitor; 4 | 5 | public interface VisitorService { 6 | boolean insert(Visitor visitor); 7 | int countVisitor(); 8 | int todayVisitor(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/test/test.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | public class test { 4 | public static void main(String[] args) { 5 | System.out.println("李浩飞"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/test/testLog4j.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import jdk.nashorn.internal.objects.annotations.Property; 4 | import org.apache.log4j.BasicConfigurator; 5 | import org.apache.log4j.Logger; 6 | import org.apache.log4j.PropertyConfigurator; 7 | 8 | public class testLog4j { 9 | static Logger logger = Logger.getLogger(testLog4j.class); 10 | public static void main(String[] args) throws InterruptedException { 11 | // PropertyConfigurator.configure("log4j.properties"); 12 | // BasicConfigurator.configure(); 13 | // for (int i = 0; i < 50; i++) { 14 | // logger.trace("跟踪信息"); 15 | // logger.debug("调试信息"); 16 | // logger.info("输出信息"); 17 | // logger.warn("警告信息"); 18 | // logger.error("错误信息"); 19 | // logger.fatal("致命信息"); 20 | // } 21 | // System.out.println("调用了我"); 22 | // logger.info(args); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/test/testlog.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | public class testlog { 9 | @Autowired 10 | testtopic testtopic; 11 | @RequestMapping("test") 12 | public String test(){ 13 | testtopic.testTopic(); 14 | return "cate"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/test/testsignup.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class testsignup { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/test/testtopic.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import dao.TopicMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import pojo.Topic; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class testtopic { 12 | @Autowired 13 | TopicMapper topicMapper; 14 | 15 | public List testTopic(){ 16 | System.out.println(topicMapper); 17 | List topics=topicMapper.listTopicsAndUsers(); 18 | // List topics=new ArrayList(); 19 | System.out.println(topics.size()); 20 | return topics; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/util/HexConversion.java: -------------------------------------------------------------------------------- 1 | package util; 2 | /** 3 | * 二进制转十六进制 4 | */ 5 | public class HexConversion { 6 | static String bytesToHex(byte[] bytes){ 7 | StringBuffer str=new StringBuffer(); 8 | int num; 9 | for (int i=0;i 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | driver=com.mysql.jdbc.Driver 2 | url=jdbc:mysql://localhost:3306/forum?useUnicode=true&autoReconnect=true&characterEncoding=utf8 3 | name=root 4 | password=admin -------------------------------------------------------------------------------- /src/main/resources/log/Lhfly.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/resources/log/Lhfly.log -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,stdout,file 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Threshold=DEBUG 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} - %m%n 6 | 7 | #one log file a day 8 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 9 | log4j.appender.file.Threshold=DEBUG 10 | log4j.appender.file.File=H:\\IDEAproject\\BBS\\src\\main\\resources\\log\\Lhfly.log 11 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 12 | log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1} - %m%n 13 | -------------------------------------------------------------------------------- /src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/resources/springMVC.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | /common/error_fileupload 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | 404 Not Find:( 7 | 143 | 144 | 145 |
146 |

404 Not Find:(

147 |

对不起,您访问的页面不存在~

148 |

请输入正确的地址

149 |

5秒后,自动跳转到上一页

150 | 161 |
162 | 163 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/cate.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | Lhfly - 一个分享创造的开发者社区 9 | 10 | 11 | 12 | 55 | 56 | 57 | 58 | <%@ include file="header.jsp"%> 59 |
60 |
61 | 66 | 67 | 91 |
92 |
93 | <%@include file="../jsp/page.jsp" %> 94 |
95 |
96 |
97 | 98 | <%@ include file="side.jsp"%> 99 |
100 | 101 | 102 | 103 | <%@ include file="footer.jsp"%> 104 | 105 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/detail.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 3 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ${topic.title} - Genesis 12 | 13 | 14 | 15 | <%@ include file="header.jsp"%> 16 |
17 |
18 |
19 |
20 |
21 | Lhfly › 主题 22 |
23 |

[ 精品 ]

${topic.title}


24 |
25 |
26 | 27 |
28 | ${topic.user.username}   29 | 创建于: ${topic.localCreateTime}      30 | 阅读量: ${topic.click} 31 |

删除主题  

32 |

取消精品  

33 |

添加精品  

34 |
35 |
36 | 37 | 38 |
39 | 40 |
    41 |
  • 42 | ${topic.content} 43 |
  • 44 |
45 |
46 | 47 | 48 |
49 |
50 | 51 | 评论数: ${fn:length(replies)} | 最新评论: 52 | 53 | 54 | ${reply.localCreateTime} 55 | 56 | 57 | 58 |
59 | 60 |
    61 | 62 | 63 |
  • 64 |
    65 |
    66 | 67 |
    68 |
    69 | ${reply.user.username}   70 | ${reply.localCreateTime} 71 |

    删除回复

    72 |
    73 |
    74 |

    ${reply.content}

    75 |
    76 |
    77 |
    78 |
  • 79 |
    80 | 81 |
82 |
83 |
84 | 85 | 86 | 87 |
88 |
89 | 添加一条新回复 90 |
91 |
92 |
93 |
94 | 95 | 96 |
97 | 98 |
99 |
100 | 101 |
102 |
103 |
104 | 105 |
106 |
107 | 108 | <%@ include file="side.jsp"%> 109 |
110 | 111 | 112 | <%@ include file="footer.jsp"%> 113 | 150 | 151 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/footer.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 47 | 48 | 49 |
50 |
51 | Lhfly是一个认真而有趣的社区,不同的人在上面分享自己的见解 52 |


53 |

Designed by lhf2018

54 |
55 |
56 |

统计信息

57 |
    58 |
  • 总访问量: ${visitorNum}
  • 59 |
  • 今日访问量: ${todayVisitor}
  • 60 |
  • 会员数: ${usersNum}
  • 61 |
  • 话题数: ${topicsNum}
  • 62 |
63 |
64 |
65 |

友情链接

66 | 71 |
72 |
73 |

其他信息

74 | 78 |
79 |
80 | 81 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/header.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 |
5 | 59 | 60 | 61 |
62 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/message.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Lhfly › <c:if test="${!empty userInfo}">${userInfo.username}</c:if><c:if test="${!empty errorInfo}">会员未找到</c:if> 11 | 12 | 13 | 14 | <%@ include file="header.jsp"%> 15 | 16 |
17 |
18 |
19 | Lhfly › 消息列表     共有消息 ${messNum} 条,未读消息 ${unreadMessage} 条 20 |
21 | 22 |
23 | 24 | 44 | 45 | 46 | 没有未读消息 47 | 48 |
49 |
50 |
51 | <%@include file="../jsp/page.jsp" %> 52 |
53 |
54 |
55 | 56 | <%@ include file="side.jsp"%> 57 |
58 | 59 | 60 | <%@ include file="footer.jsp"%> 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/new.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 创作新主题 › Lhfly 11 | 12 | 13 | 14 | <%@ include file="header.jsp"%> 15 | 16 |
17 |
18 |
19 | Lhfly › 创作新主题 20 |
21 | 22 |
23 |
24 |
25 | 26 | 27 |
28 |
29 | 30 | 31 |
32 | 33 |
34 |
35 |
36 | 41 |
42 |

43 |
44 |
45 | 46 |
47 | 48 |
49 |
50 | 51 |
52 | 53 | 54 | 55 |
56 | 57 | 58 |
59 |
60 | 发帖提示 61 |
62 |
    63 |
  • 64 |
    主题标题
    65 |

    66 | 请在标题中描述内容要点。如果一件事情在标题的长度内就已经可以说清楚,那就没有必要写正文了。 67 |

    68 |
  • 69 | 70 |
  • 71 |
    正文
    72 |

    73 | 请清楚地表达所要说明的内容。 74 |

    75 |
  • 76 |
77 |
78 | 79 | 80 |
81 |
82 | 社区指导原则 83 |
84 |
    85 |
  • 86 |
    尊重原创
    87 |

    88 | 请不要发布任何盗版下载链接,包括软件、音乐、电影等等。Lhfly是创意工作者的社区,我们尊重原创。 89 |

    90 |
  • 91 | 92 |
  • 93 |
    友好互助
    94 |

    95 | 保持对陌生人的友善。用知识去帮助别人。 96 |

    97 |
  • 98 |
99 |
100 | 101 | 102 | 103 | <%@ include file="footer.jsp"%> 104 | 105 | 123 | 124 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/page.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html;charset=UTF-8" 2 | pageEncoding="UTF-8" isELIgnored="false"%> 3 | 4 | 5 | 13 | 14 | 15 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/settings.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Genesis ›设置 11 | 12 | 13 | 14 | <%@ include file="header.jsp"%> 15 | 16 |
17 |
18 |
19 | Lhfly › 设置 20 |
21 | 22 |
23 | 24 |
25 |
26 | 27 | 更换头像 28 |
29 |
30 | 31 |
32 |

${user.id}

33 |
34 |
35 |
36 | 37 |
38 |

${user.username}

39 |
40 |
41 |
42 | 43 |
44 |

${user.email}

45 |
46 |
47 |
48 | 49 |
50 |

${user.localCreateTime}

51 |
52 |
53 |
54 | 55 |
56 |

${user.credit}

57 |
58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 | 66 | 67 | 68 |
69 | 70 |
71 | 72 | <%@ include file="side.jsp"%> 73 |
74 | 75 | <%@ include file="footer.jsp"%> 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/side.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 |
9 |
10 |
11 | Lhfly 12 | 一个分享创造的开发者社区 13 |
14 |
15 | 21 |
22 |
23 | 24 | 25 | 26 | 36 | 37 | 38 |
39 |
40 | 热议主题 41 |
42 | 47 |
48 | 49 | 50 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/signin.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 登录 - Genesis 8 | 9 | 10 | 11 | 12 | 13 | 53 | 54 | 55 | 56 | <%@ include file="header.jsp"%> 57 | 58 |
59 |
60 |

登录

61 |
62 |
63 | 64 |
65 | 66 | 67 |
68 |
69 | 70 | 71 |
72 |
73 | 76 | 忘记密码? 77 |
78 | 79 |


80 | 81 | 82 | 83 |
84 |
85 | 160 | 161 | <%@ include file="footer.jsp"%> 162 | 163 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/signup.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 注册 - Lhfly 8 | 9 | 10 | 11 | 51 | 52 | 53 | 54 | 55 | 56 | <%@ include file="header.jsp"%> 57 | 58 |
59 |
60 |

注册

61 |
62 |
63 |
64 |
65 | 66 |
67 | 68 | 69 | 70 | ${errorMessage} 71 | 72 |

请使用半角的 a-z 或数字 0-9

73 |
74 |
75 |
76 | 77 |
78 | 79 |
80 |
81 |
82 | 83 |
84 | 85 |
86 |
87 | 88 |
89 | 90 |
91 | 96 |
97 |
98 | 99 |
100 | 101 |
102 | 103 |
104 |
105 | 106 |
107 |
108 |
109 | 110 | <%@ include file="footer.jsp"%> 111 | 112 | 145 | 146 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/update_avatar.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Lhfly ›头像上传 11 | 12 | 13 | 14 | <%@ include file="header.jsp"%> 15 | 16 |
17 |
18 |
19 | Lhfly › 设置 ›头像上传 20 |
21 | 22 |
23 | 24 |
25 |
26 | 27 | 28 |
29 | 30 |
31 |
32 | 33 |
34 | 35 |
36 | 37 | 38 | 39 |
40 | 41 | 42 | <%@ include file="side.jsp"%> 43 | 44 | 45 | <%@ include file="footer.jsp"%> 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/user_info.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Lhfly › <c:if test="${!empty userInfo}">${userInfo.username}</c:if><c:if test="${!empty errorInfo}">会员未找到</c:if> 11 | 12 | 13 | 14 | <%@ include file="header.jsp"%> 15 | 16 |
17 |
18 |
19 | Lhfly › ${userInfo.username} 20 |
21 | 22 |
23 | 24 |
25 |
26 | 27 |

28 |
29 | 30 |
31 |

${userInfo.id}

32 |
33 |
34 |
35 | 36 |
37 |

${userInfo.username}

38 |
39 |
40 |
41 | 42 |
43 |

${userInfo.email}

44 |
45 |
46 |
47 | 48 |
49 |

${userInfo.localCreateTime}

50 |
51 |
52 |
53 | 54 |
55 |

${userInfo.credit}

56 |
57 |
58 |
59 |
60 | 61 | 会员未找到! 62 | 63 |
64 |
65 |
66 | 67 |
68 | 69 | <%@ include file="side.jsp"%> 70 |
71 | 72 | 73 | <%@ include file="footer.jsp"%> 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | contextConfigLocation 11 | classpath:applicationContext.xml 12 | 13 | 14 | 15 | 16 | org.springframework.web.context.ContextLoaderListener 17 | 18 | 19 | 20 | 21 | CharacterEncodingFilter 22 | org.springframework.web.filter.CharacterEncodingFilter 23 | 24 | encoding 25 | UTF-8 26 | 27 | 28 | 29 | CharacterEncodingFilter 30 | /* 31 | 32 | 33 | 34 | 35 | 36 | main 37 | 38 | org.springframework.web.servlet.DispatcherServlet 39 | 40 | 41 | contextConfigLocation 42 | classpath*:springMVC.xml 43 | 44 | 1 45 | 46 | 47 | 48 | main 49 | / 50 | 51 | 52 | CORSFilter 53 | intercepter.CORSFilter 54 | 55 | 56 | CORSFilter 57 | /* 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/main/webapp/static/css/front-common.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | font-size: 14px; 4 | color: #525252; 5 | font-family: NotoSansHans-Regular,AvenirNext-Regular,arial,Hiragino Sans GB,"Microsoft Yahei","Hiragino Sans GB","WenQuanYi Micro Hei",sans-serif; 6 | background: #f0f2f5; 7 | } -------------------------------------------------------------------------------- /src/main/webapp/static/css/front-footer.css: -------------------------------------------------------------------------------- 1 | li {list-style-type:none;} 2 | html, body { 3 | height: 100%; 4 | font-size: 14px; 5 | color: #525252; 6 | font-family: NotoSansHans-Regular,AvenirNext-Regular,arial,Hiragino Sans GB,"Microsoft Yahei","Hiragino Sans GB","WenQuanYi Micro Hei",sans-serif; 7 | background: #f0f2f5; 8 | } 9 | .footer { 10 | background-color: #fff; 11 | margin-top: 22px; 12 | margin-bottom: 22px; 13 | width: 100%; 14 | padding-top: 22px; 15 | color: #8A8A8A; 16 | display: block; 17 | height: 200px; 18 | border: 1px ; 19 | } 20 | 21 | .container { 22 | margin-right: 5%; 23 | margin-left: 5%; 24 | padding-left: 15px; 25 | padding-right: 15px; 26 | width: 40%; 27 | float: left; 28 | } 29 | .info { 30 | margin-right: 5%; 31 | width: 10%; 32 | float: left; 33 | } 34 | a{ 35 | color: #8A8A8A; 36 | cursor: pointer; 37 | } -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/1521949392720-2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/1521949392720-2.PNG -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-1.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-10.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-11.png: -------------------------------------------------------------------------------- 1 | LHFNB 2 | -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-2.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-3.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-4.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-5.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-6.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-7.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-8.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/avatar/avatar-default-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/avatar/avatar-default-9.png -------------------------------------------------------------------------------- /src/main/webapp/static/img/background/timg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhf2018/Lhfly-BBS/d588cc9c3841ad1c47b98e18209b6481f017e45d/src/main/webapp/static/img/background/timg.jpg -------------------------------------------------------------------------------- /src/main/webapp/static/img/icon/heart.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Svg Vector Icons : http://www.sfont.cn 6 | 7 | -------------------------------------------------------------------------------- /src/main/webapp/static/img/icon/magnifying-glass.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /src/main/webapp/static/js/js.cookie.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * JavaScript Cookie v2.1.4 3 | * https://github.com/js-cookie/js-cookie 4 | * 5 | * Copyright 2006, 2015 Klaus Hartl & Fagner Brack 6 | * Released under the MIT license 7 | */ 8 | ;(function (factory) { 9 | var registeredInModuleLoader = false; 10 | if (typeof define === 'function' && define.amd) { 11 | define(factory); 12 | registeredInModuleLoader = true; 13 | } 14 | if (typeof exports === 'object') { 15 | module.exports = factory(); 16 | registeredInModuleLoader = true; 17 | } 18 | if (!registeredInModuleLoader) { 19 | var OldCookies = window.Cookies; 20 | var api = window.Cookies = factory(); 21 | api.noConflict = function () { 22 | window.Cookies = OldCookies; 23 | return api; 24 | }; 25 | } 26 | }(function () { 27 | function extend () { 28 | var i = 0; 29 | var result = {}; 30 | for (; i < arguments.length; i++) { 31 | var attributes = arguments[ i ]; 32 | for (var key in attributes) { 33 | result[key] = attributes[key]; 34 | } 35 | } 36 | return result; 37 | } 38 | 39 | function init (converter) { 40 | function api (key, value, attributes) { 41 | var result; 42 | if (typeof document === 'undefined') { 43 | return; 44 | } 45 | 46 | // Write 47 | 48 | if (arguments.length > 1) { 49 | attributes = extend({ 50 | path: '/' 51 | }, api.defaults, attributes); 52 | 53 | if (typeof attributes.expires === 'number') { 54 | var expires = new Date(); 55 | expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); 56 | attributes.expires = expires; 57 | } 58 | 59 | // We're using "expires" because "max-age" is not supported by IE 60 | attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; 61 | 62 | try { 63 | result = JSON.stringify(value); 64 | if (/^[\{\[]/.test(result)) { 65 | value = result; 66 | } 67 | } catch (e) {} 68 | 69 | if (!converter.write) { 70 | value = encodeURIComponent(String(value)) 71 | .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); 72 | } else { 73 | value = converter.write(value, key); 74 | } 75 | 76 | key = encodeURIComponent(String(key)); 77 | key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); 78 | key = key.replace(/[\(\)]/g, escape); 79 | 80 | var stringifiedAttributes = ''; 81 | 82 | for (var attributeName in attributes) { 83 | if (!attributes[attributeName]) { 84 | continue; 85 | } 86 | stringifiedAttributes += '; ' + attributeName; 87 | if (attributes[attributeName] === true) { 88 | continue; 89 | } 90 | stringifiedAttributes += '=' + attributes[attributeName]; 91 | } 92 | return (document.cookie = key + '=' + value + stringifiedAttributes); 93 | } 94 | 95 | // Read 96 | 97 | if (!key) { 98 | result = {}; 99 | } 100 | 101 | // To prevent the for loop in the first place assign an empty array 102 | // in case there are no cookies at all. Also prevents odd result when 103 | // calling "get()" 104 | var cookies = document.cookie ? document.cookie.split('; ') : []; 105 | var rdecode = /(%[0-9A-Z]{2})+/g; 106 | var i = 0; 107 | 108 | for (; i < cookies.length; i++) { 109 | var parts = cookies[i].split('='); 110 | var cookie = parts.slice(1).join('='); 111 | 112 | if (cookie.charAt(0) === '"') { 113 | cookie = cookie.slice(1, -1); 114 | } 115 | 116 | try { 117 | var name = parts[0].replace(rdecode, decodeURIComponent); 118 | cookie = converter.read ? 119 | converter.read(cookie, name) : converter(cookie, name) || 120 | cookie.replace(rdecode, decodeURIComponent); 121 | 122 | if (this.json) { 123 | try { 124 | cookie = JSON.parse(cookie); 125 | } catch (e) {} 126 | } 127 | 128 | if (key === name) { 129 | result = cookie; 130 | break; 131 | } 132 | 133 | if (!key) { 134 | result[name] = cookie; 135 | } 136 | } catch (e) {} 137 | } 138 | 139 | return result; 140 | } 141 | 142 | api.set = api; 143 | api.get = function (key) { 144 | return api.call(api, key); 145 | }; 146 | api.getJSON = function () { 147 | return api.apply({ 148 | json: true 149 | }, [].slice.call(arguments)); 150 | }; 151 | api.defaults = {}; 152 | 153 | api.remove = function (key, attributes) { 154 | api(key, '', extend(attributes, { 155 | expires: -1 156 | })); 157 | }; 158 | 159 | api.withConverter = init; 160 | 161 | return api; 162 | } 163 | 164 | return init(function () {}); 165 | })); 166 | --------------------------------------------------------------------------------