前言
分享一个SSM的实战项目,一个使用springmvc,mybatis,jequery,bootstrap,ueditor打造的论坛系统,主要包含论坛主体,后台管理两个部分。
git地址如下:github.com/jsbintask22…
技术介绍
该系统主要使用服务端主要使用spring,mybatis进行搭建,前端主要为bootstrap,jquery编写的jsp页面,并且集成百度ueditor进行富文本编辑,功能实现,技术点如下:
用户注册:用户如若要进行发帖,回帖等操作,必须先注册账号。注册账号使用邮箱进行注册(邮件发送),使用ajax验证邮箱,用户名唯一性。
用户登录: 用户登录需输入验证码,验证码为请求登陆页面时后台生成图片,记录到session中。
权限验证:系统中某些行为必须进行登陆方可操作,所以必须提供同意权限验证,此系统主要使用拦截器(Interceptor)进行用户的权限验证。
用户发帖:已登陆的用户可以进行发帖,回帖。提供直接图片,文件上传功能,此处前端使用UEDITOR配合后端文件上传实现。
用户回帖:用户可以回复某一帖子,并且可以引用。所以此处设计数据库设计 树状结构的表设计。
帖子收藏:用户可以收藏喜欢的帖子,并且在个人中心中找到。
用户关注:用户可以关注其他用户。
个人信息:用户可以查看个人信息,修改维护个人信息,并且设置头像。
帖子管理:后台主要功能为对帖子进行维护,可以及时删除,恢复已经存在的帖子。
关键代码讲解
pom文件
4.0.0
<groupId>cn.jsbintask</groupId>
<artifactId>jsbintask-bbs</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>jsbintask-bbs Maven Webapp</name>
<url>http://jsbintask.cn</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<org.springframework.version>4.3.10.RELEASE</org.springframework.version>
<org.mybatis.version>3.4.1</org.mybatis.version>
<org.mybatis.spring.version>1.3.0</org.mybatis.spring.version>
</properties>
<developers>
<developer>
<email>jsbintask@gmail.com</email>
<name>jsbintask</name>
<url>https://jsbintask.cn</url>
<roles>
<role>developer</role>
</roles>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<scope>provided</scope>
<version>8.5.11</version>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- hibernate验证jar-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<!--aop实现-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<!--mybatisjar-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${org.mybatis.spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jstl/jstl -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${org.mybatis.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.baidu</groupId>
<artifactId>ueditor-mini</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ueditor-mini.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
<build>
<finalName>jsbintask-bbs</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
复制代码此处值得注意的是,由于百度ueditor未在中央仓库中提供相关jar文件,所以此处为引用本地jar(见项目结构) web.xml <?xml version="1.0" encoding="UTF-8"?>
<display-name>bbs</display-name>
<!--配置一个首页-->
<welcome-file-list>
<welcome