diff --git a/.gitignore b/.gitignore
index fb6851a..8c293a4 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,9 @@
# 忽略.idea文件夹下的项目信息文件
.idea
+
+# 忽略classes目录
+target/
+*/target/
+
+# 忽略工程文件
+*.iml
diff --git a/JavaPracticeCode.iml b/JavaPracticeCode.iml
deleted file mode 100644
index 8979886..0000000
--- a/JavaPracticeCode.iml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.MD b/README.MD
index 71af03a..edef856 100644
--- a/README.MD
+++ b/README.MD
@@ -1,5 +1,8 @@
### Java学习代码仓库
+#### 模块目录
+* 用Spring实现的一个论坛的基本功能(spring-bbs-demo)
+
#### 项目初始化
新建一个maven工程,使用了公司的仓库模板,过程大概如下:
* 1.new->project->maven->create from archetype->maven-archetype-quickstart
@@ -70,3 +73,15 @@ To push the current branch and set the remote as upstream, use
~/JavaPracticeCode git push origin master
Everything up-to-date
```
+添加spring配置
+```xml
+
+
+
+
+ file://$MODULE_DIR$/src/main/resources/config.xml
+
+
+
+
+```
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 407125c..4d549ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,25 +1,149 @@
- 4.0.0
-
- com.learn.note.practice
- code
- 1.0-SNAPSHOT
- jar
-
- code
- http://maven.apache.org
-
-
- UTF-8
-
-
-
-
- junit
- junit
- 3.8.1
- test
-
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ com.learn.note.practice
+ code
+ 1.0-SNAPSHOT
+
+ spring-bbs-demo
+
+ pom
+
+ code
+ http://maven.apache.org
+
+
+ UTF-8
+ 4.11
+ 1.7.7
+ 1.0.13
+ 4.0.0.RELEASE
+ 1.8.0
+ 5.1.34
+ 1.2.2
+ 3.1.0
+ 1.1.2
+
+
+
+
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+ org.springframework
+ spring-test
+ ${spring.version}
+ test
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+ ch.qos.logback
+ logback-core
+ ${logback.version}
+
+
+
+
+ org.springframework
+ spring-aop
+ ${spring.version}
+
+
+ org.springframework
+ spring-beans
+ ${spring.version}
+
+
+ org.springframework
+ spring-context
+ ${spring.version}
+
+
+ org.springframework
+ spring-core
+ ${spring.version}
+
+
+ org.springframework
+ spring-jdbc
+ ${spring.version}
+
+
+ org.springframework
+ spring-web
+ ${spring.version}
+
+
+ org.springframework
+ spring-webmvc
+ ${spring.version}
+
+
+ org.springframework
+ spring-tx
+ ${spring.version}
+
+
+
+
+ org.aspectj
+ aspectjweaver
+ ${aspectj.version}
+
+
+
+
+ mysql
+ mysql-connector-java
+ ${mysql.version}
+
+
+
+ commons-dbcp
+ commons-dbcp
+ ${dhcp.version}
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ ${servlet.version}
+
+
+
+
+ jstl
+ jstl
+ ${jstl.version}
+
+
+
+ taglibs
+ standard
+ ${jstl.version}
+
+
+
+
+
+
diff --git a/spring-bbs-demo/README.MD b/spring-bbs-demo/README.MD
new file mode 100644
index 0000000..b917db4
--- /dev/null
+++ b/spring-bbs-demo/README.MD
@@ -0,0 +1,196 @@
+### 用spring实现一个论坛基本功能
+
+#### 运行环境
+Linux:Ubun 14.04 64bit
+IDE:IntelliJ IDEA 14.03
+JDK:1.7.40
+MySQL:5.5.44
+Tomcat:7.0.47
+Maven:3.0.5
+
+#### 展现层
+
+使用`Spring-MVC`,具体步骤如下:
+先配置web.xml文件,在`webapp`的`WEB-INF`目录下
+```xml
+
+
+
+
+
+ contextConfigLocation
+ classpath:applicationContext.xml
+
+
+
+
+ org.springframework.web.context.ContextLoaderListener
+
+
+
+
+ baobaotao
+ org.springframework.web.servlet.DispatcherServlet
+ 2
+
+
+
+ baobaotao
+ *.html
+
+
+ Archetype Created Web Application
+
+
+```
+
+配置文件
+```xml
+
+ baobaotao
+ org.springframework.web.servlet.DispatcherServlet
+ 2
+
+```
+虽然这个servlet名字可以随意取,但是一般有个约定,就是还必须有一个-servlet.xml的配置文件,即在同目录下
+还需要有一个`baobaotao-servlet.xml`的Spring-mvc配置文件。不过不需要再定义在web.xml文件中,Spring MVC会自动将这些文件
+加载。
+
+`*.html`指定拦截*.html的文件,一般喜欢使用*.do和*.action的后缀,但是使用.html后缀有几个好处。
+第一:用户不能根据url判断我们使用的是什么技术
+第二:*.html是静态网页后缀,可以骗过搜索引擎,增加被收录的概率
+同时对于那些真正的静态网页可以使用*.htm加以区分
+
+Spring MVC
+这个东西主要负责控制业务逻辑,即后台代码的逻辑页面跳转等控制,我们需要写一个Controller来进行控制
+先写一个`LoginController`
+```java
+@Controller //标注成为一个Spring MVC的Controller 处理http请求
+public class LoginController {
+
+ @Autowired
+ private UserService userService;
+
+ /**
+ * 负责处理/index.html的请求
+ */
+ @RequestMapping(value = "/index.html")
+ public String loginPage() {
+ return "login";
+ }
+
+ /**
+ * 登陆验证视图
+ * @param loginCommand 扥路信息
+ */
+ @RequestMapping(value = "/loginCheck.html")
+ public ModelAndView loginCheck(HttpServletRequest request, LoginCommand loginCommand) {
+ boolean isValidUser = userService.hasMatchUser(
+ loginCommand.getUserName(), loginCommand.getPassword());
+
+ if (!isValidUser) {
+ return new ModelAndView("login", "error", "用户名或密码错误");
+ } else {
+ User user = userService.findUserByUserName(loginCommand.getUserName());
+ user.setLastIp(request.getLocalAddr());
+ user.setLastVistit(new Date());
+ userService.loginSucess(user);
+
+ request.getSession().setAttribute("user", user);
+ return new ModelAndView("main");
+ }
+ }
+}
+```
+**NOTE:** `@Controller`标注的类也是一个`Bean`,所以在Controller里进行注入,控制器中可以映射多个不同的http请求路径,通过
+`@RequestMapping`指定路径。其中请求的参数会自动的绑定到响应方法的入参中,这个绑定是按照名字来绑定的,请求响应方法可以返回一个
+`ModelAndView`或者字符串,然后`Spring MVC`会自动解析做相应跳转。并且`ModelAndView`对象不仅包括了视图信息,也包含了渲染所需模型数据
+
+#### Spring MVC配置文件
+光写一个`Controller`还不够,还需要在`springbbs-servlet.xml`文件中申明我们写的控制器,扫描web路径,指定`Spring MVC`的
+视图解析器,代码如下:
+```xml
+
+
+
+
+
+
+
+
+
+```
+Spring MVC如何将视图逻辑名解析成具体视图?上面的bean即定义解析规则,可以有多种选择,这里使用的是`InternalResourceViewResolver`
+它的工作方式就是为视图逻辑名添加前后缀的方式进行解析。举个例子,逻辑名为`login`,对应的解析为`/WEB-INF/jsp/login.jsp`。
+
+### JSP视图页面
+两个页面分别为登陆页面`login.jsp`以及`main.jsp`。
+
+* login.jsp
+```jsp
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%--
+ Created by IntelliJ IDEA.
+ User: junqiangshen
+ Date: 15-9-16
+ Time: 下午11:38
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ Spring样例演示论坛登陆界面
+
+
+
+
+
+
+ " method="post">
+ 用户名:
+
+
+ 密码:
+
+
+
+
+
+
+
+```
+
+登陆成功界面
+```jsp
+<%--
+ Created by IntelliJ IDEA.
+ User: junqiangshen
+ Date: 15-9-16
+ Time: 下午11:38
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+ Spring 测试论坛
+
+
+ ${user.userName},欢迎进入Spring 样例论坛,您当前积分为${user.credits};
+
+
+```
diff --git a/spring-bbs-demo/pom.xml b/spring-bbs-demo/pom.xml
new file mode 100644
index 0000000..9ba5ee6
--- /dev/null
+++ b/spring-bbs-demo/pom.xml
@@ -0,0 +1,116 @@
+
+
+ code
+ com.learn.note.practice
+ 1.0-SNAPSHOT
+
+ 4.0.0
+ spring-bbs-demo
+ war
+ spring-bbs-demo Maven Webapp
+ http://maven.apache.org
+
+
+
+
+ junit
+ junit
+ test
+
+
+ org.springframework
+ spring-test
+ test
+
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
+
+ ch.qos.logback
+ logback-core
+
+
+
+
+ org.springframework
+ spring-aop
+
+
+ org.springframework
+ spring-beans
+
+
+ org.springframework
+ spring-context
+
+
+ org.springframework
+ spring-core
+
+
+ org.springframework
+ spring-jdbc
+
+
+ org.springframework
+ spring-tx
+
+
+ org.springframework
+ spring-web
+
+
+ org.springframework
+ spring-webmvc
+
+
+
+
+ org.aspectj
+ aspectjweaver
+ ${aspectj.version}
+
+
+
+
+ mysql
+ mysql-connector-java
+
+
+
+ commons-dbcp
+ commons-dbcp
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+
+
+
+
+ jstl
+ jstl
+
+
+
+ taglibs
+ standard
+
+
+
+
+
+ spring-bbs-demo
+
+
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/controller/LoginController.java b/spring-bbs-demo/src/main/java/com/springbbs/controller/LoginController.java
new file mode 100644
index 0000000..a1c1b5c
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/controller/LoginController.java
@@ -0,0 +1,53 @@
+package com.springbbs.controller;
+
+import com.springbbs.domain.LoginCommand;
+import com.springbbs.domain.User;
+import com.springbbs.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+
+/**
+ * @Description JavaPracticeCode
+ * Created by junqiangshen on 15-8-31.
+ */
+@Controller //标注成为一个Spring MVC的Controller
+public class LoginController {
+
+ @Autowired
+ private UserService userService;
+
+ /**
+ * 负责处理/index.html的请求
+ */
+ @RequestMapping(value = "/index.html")
+ public String loginPage() {
+ return "login";
+ }
+
+ /**
+ * 登陆验证视图
+ * @param loginCommand 扥路信息
+ */
+ @RequestMapping(value = "/loginCheck.html")
+ public ModelAndView loginCheck(HttpServletRequest request, LoginCommand loginCommand) {
+ boolean isValidUser = userService.hasMatchUser(
+ loginCommand.getUserName(), loginCommand.getPassword());
+
+ if (!isValidUser) {
+ return new ModelAndView("login", "error", "用户名或密码错误");
+ } else {
+ User user = userService.findUserByUserName(loginCommand.getUserName());
+ user.setLastIp(request.getLocalAddr());
+ user.setLastVistit(new Date());
+ userService.loginSucess(user);
+
+ request.getSession().setAttribute("user", user);
+ return new ModelAndView("main");
+ }
+ }
+}
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/dao/LoginLogDao.java b/spring-bbs-demo/src/main/java/com/springbbs/dao/LoginLogDao.java
new file mode 100644
index 0000000..1042021
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/dao/LoginLogDao.java
@@ -0,0 +1,24 @@
+package com.springbbs.dao;
+
+import com.springbbs.domain.LoginLog;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @Description JavaPracticeCode
+ * Created by junqiangshen on 15-8-26.
+ */
+@Repository
+public class LoginLogDao {
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ public void insertLoginLog(LoginLog loginLog) {
+ String sqlStr = "INSERT INTO t_login_log(user_id,ip,login_datetime) "
+ + "VALUES(?,?,?)";
+ Object[] args = {loginLog.getUserId(), loginLog.getIp(), loginLog.getLoginDate()};
+ jdbcTemplate.update(sqlStr, args);
+ }
+}
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/dao/UserDao.java b/spring-bbs-demo/src/main/java/com/springbbs/dao/UserDao.java
new file mode 100644
index 0000000..78091d6
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/dao/UserDao.java
@@ -0,0 +1,52 @@
+package com.springbbs.dao;
+
+import com.springbbs.domain.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowCallbackHandler;
+import org.springframework.stereotype.Repository;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @Description 访问User的类
+ * Created by junqiangshen on 15-8-26.
+ */
+@Repository //1.通过Spring注解定义一个DAO
+public class UserDao {
+
+ @Autowired //2.自动注入jdbcTemplate的Bean
+ private JdbcTemplate jdbcTemplate;
+
+ public int getMatchCount(String userName, String password) {
+ String sqlStr = "SELECT count(*) FROM t_user "
+ + "WHERE user_name=? and password=?";
+ return jdbcTemplate.queryForObject(sqlStr, new Object[]{userName, password}, Integer.class);
+ }
+
+ public User findUserByUserName(final String userName) {
+ String sqlStr = "SELECT user_id,user_name,credits "
+ + "FROM t_user WHERE user_name=?";
+ final User user = new User();
+ jdbcTemplate.query(sqlStr, new Object[]{userName},
+ new RowCallbackHandler() {
+ @Override
+ public void processRow(ResultSet resultSet) throws SQLException {
+ user.setUserId(resultSet.getInt("user_id"));
+ user.setUserName(userName);
+ user.setCredits(resultSet.getInt("credits"));
+ }
+ }
+ );
+
+ return user;
+ }
+
+ public void updateLoginInfo(User user) {
+ String sqlStr = "UPDATE t_user SET last_visit=?,last_ip=?,credits=? "
+ + "WHERE user_id=?";
+ jdbcTemplate.update(sqlStr, new Object[]{user.getLastVistit(),
+ user.getLastIp(), user.getCredits(), user.getUserId()});
+ }
+}
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/domain/LoginCommand.java b/spring-bbs-demo/src/main/java/com/springbbs/domain/LoginCommand.java
new file mode 100644
index 0000000..ea330ea
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/domain/LoginCommand.java
@@ -0,0 +1,38 @@
+package com.springbbs.domain;
+
+import java.io.Serializable;
+
+/**
+ * @Description JavaPracticeCode
+ * Created by junqiangshen on 15-8-31.
+ */
+public class LoginCommand implements Serializable{
+ private static final long serialVersionUID = 1556475033994145521L;
+
+ private String userName;
+ private String password;
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @Override
+ public String toString() {
+ return "LoginCommand{" +
+ "userName='" + userName + '\'' +
+ ", password='" + password + '\'' +
+ '}';
+ }
+}
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/domain/LoginLog.java b/spring-bbs-demo/src/main/java/com/springbbs/domain/LoginLog.java
new file mode 100644
index 0000000..844049c
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/domain/LoginLog.java
@@ -0,0 +1,59 @@
+package com.springbbs.domain;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @Description 登陆日志实体类
+ * Created by junqiangshen on 15-8-26.
+ */
+public class LoginLog implements Serializable {
+ private static final long serialVersionUID = 1141217463557201669L;
+
+ private int loginLogId;
+ private int userId;
+ private String ip;
+ private Date loginDate;
+
+ public int getLoginLogId() {
+ return loginLogId;
+ }
+
+ public void setLoginLogId(int loginLogId) {
+ this.loginLogId = loginLogId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(int userId) {
+ this.userId = userId;
+ }
+
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ public Date getLoginDate() {
+ return loginDate;
+ }
+
+ public void setLoginDate(Date loginDate) {
+ this.loginDate = loginDate;
+ }
+
+ @Override
+ public String toString() {
+ return "LoginLog{" +
+ "loginLogId=" + loginLogId +
+ ", userId=" + userId +
+ ", ip='" + ip + '\'' +
+ ", loginDate=" + loginDate +
+ '}';
+ }
+}
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/domain/User.java b/spring-bbs-demo/src/main/java/com/springbbs/domain/User.java
new file mode 100644
index 0000000..cb072b9
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/domain/User.java
@@ -0,0 +1,79 @@
+package com.springbbs.domain;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @Description User实体类
+ * Created by junqiangshen on 15-8-26.
+ */
+public class User implements Serializable {
+ private static final long serialVersionUID = 3628238945647868396L;
+
+ private int userId;
+ private String userName;
+ private String password;
+ private int credits;
+ private String lastIp;
+ private Date lastVistit;
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(int userId) {
+ this.userId = userId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public int getCredits() {
+ return credits;
+ }
+
+ public void setCredits(int credits) {
+ this.credits = credits;
+ }
+
+ public String getLastIp() {
+ return lastIp;
+ }
+
+ public void setLastIp(String lastIp) {
+ this.lastIp = lastIp;
+ }
+
+ public Date getLastVistit() {
+ return lastVistit;
+ }
+
+ public void setLastVistit(Date lastVistit) {
+ this.lastVistit = lastVistit;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" +
+ "userId=" + userId +
+ ", userName='" + userName + '\'' +
+ ", password='" + password + '\'' +
+ ", credits=" + credits +
+ ", lastIp='" + lastIp + '\'' +
+ ", lastVistit=" + lastVistit +
+ '}';
+ }
+}
diff --git a/spring-bbs-demo/src/main/java/com/springbbs/service/UserService.java b/spring-bbs-demo/src/main/java/com/springbbs/service/UserService.java
new file mode 100644
index 0000000..ec307fd
--- /dev/null
+++ b/spring-bbs-demo/src/main/java/com/springbbs/service/UserService.java
@@ -0,0 +1,43 @@
+package com.springbbs.service;
+
+import com.springbbs.dao.LoginLogDao;
+import com.springbbs.dao.UserDao;
+import com.springbbs.domain.LoginLog;
+import com.springbbs.domain.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description 业务层,负责调用DAO层
+ * Created by junqiangshen on 15-8-27.
+ */
+@Service // 将UserService标注为一个服务层的Bean
+public class UserService {
+
+ @Autowired
+ private UserDao userDao;
+
+ @Autowired
+ private LoginLogDao loginLogDao;
+
+ public boolean hasMatchUser(String userName, String password) {
+ int matchCount = userDao.getMatchCount(userName, password);
+
+ return matchCount > 0;
+ }
+
+ public User findUserByUserName(String userName) {
+ return userDao.findUserByUserName(userName);
+ }
+
+ public void loginSucess(User user) {
+ user.setCredits(5+ user.getCredits());
+ LoginLog loginLog = new LoginLog();
+ loginLog.setUserId(user.getUserId());
+ loginLog.setIp(user.getLastIp());
+ loginLog.setLoginDate(user.getLastVistit());
+
+ userDao.updateLoginInfo(user);
+ loginLogDao.insertLoginLog(loginLog);
+ }
+}
diff --git a/spring-bbs-demo/src/main/resources/applicationContext.xml b/spring-bbs-demo/src/main/resources/applicationContext.xml
new file mode 100644
index 0000000..afe2af2
--- /dev/null
+++ b/spring-bbs-demo/src/main/resources/applicationContext.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-bbs-demo/src/main/resources/jdbc.properties b/spring-bbs-demo/src/main/resources/jdbc.properties
new file mode 100644
index 0000000..549d81e
--- /dev/null
+++ b/spring-bbs-demo/src/main/resources/jdbc.properties
@@ -0,0 +1,4 @@
+jdbc.driver=com.mysql.jdbc.Driver
+jdbc.url=jdbc:mysql://localhost:3306/sampledb
+jdbc.username=root
+jdbc.password=root0724
\ No newline at end of file
diff --git a/spring-bbs-demo/src/main/resources/sql/user_table_init.sql b/spring-bbs-demo/src/main/resources/sql/user_table_init.sql
new file mode 100644
index 0000000..cbec780
--- /dev/null
+++ b/spring-bbs-demo/src/main/resources/sql/user_table_init.sql
@@ -0,0 +1,26 @@
+DROP DATABASE IF EXISTS sampledb;
+CREATE DATABASE sampledb DEFAULT CHARACTER SET utf8mb4;
+USE sampledb;
+
+-- 创建用户表
+CREATE TABLE t_user (
+ user_id INT AUTO_INCREMENT NOT NULL COMMENT '用户id',
+ user_name VARCHAR(30) NOT NULL DEFAULT '' COMMENT '用户名',
+ credits INT NOT NULL DEFAULT 0 COMMENT '论坛积分',
+ password VARCHAR(32) NOT NULL DEFAULT ''COMMENT '用户密码',
+ last_visit TIMESTAMP NOT NULL DEFAULT 0 COMMENT '最后访问时间',
+ last_ip VARCHAR(23) NOT NULL DEFAULT '0.0.0.0' COMMENT '最后访问ip',
+ PRIMARY KEY (user_id)
+)ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT '用户表';
+
+-- 创建用户登陆日志表
+CREATE TABLE t_login_log (
+ login_log_id INT AUTO_INCREMENT NOT NULL COMMENT '日志id',
+ user_id INT NOT NULL DEFAULT 0 COMMENT '用户id',
+ ip VARCHAR(23) NOT NULL DEFAULT '0.0.0.0' COMMENT '访问ip',
+ login_datetime TIMESTAMP NOT NULL DEFAULT 0 COMMENT '访问时间',
+ PRIMARY KEY (login_log_id)
+)ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT '用户登陆日志表';
+
+INSERT INTO t_user (user_name,password) VALUES ('admin','123456');
+SELECT * FROM t_user;
\ No newline at end of file
diff --git a/spring-bbs-demo/src/main/test/java/com/springbbs/service/UserServiceTest.java b/spring-bbs-demo/src/main/test/java/com/springbbs/service/UserServiceTest.java
new file mode 100644
index 0000000..8a9a3cc
--- /dev/null
+++ b/spring-bbs-demo/src/main/test/java/com/springbbs/service/UserServiceTest.java
@@ -0,0 +1,42 @@
+package com.springbbs.service;
+
+import com.springbbs.domain.User;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import java.util.Date;
+
+@RunWith(SpringJUnit4ClassRunner.class) // 基于JUnit4的Spring测试框架
+@ContextConfiguration(locations = {"classpath:applicationContext.xml"}) //启动Spring容器
+public class UserServiceTest {
+
+ @Autowired
+ private UserService userService;
+
+ @Test
+ public void testHasMatchUser() throws Exception {
+ boolean b1 = userService.hasMatchUser("admin", "123456");
+ boolean b2 = userService.hasMatchUser("admin", "1111");
+
+ Assert.assertEquals(true, b1);
+ Assert.assertEquals(false, b2);
+ }
+
+ @Test
+ public void testFindUserByUserName() throws Exception {
+ User user = userService.findUserByUserName("admin");
+ Assert.assertEquals("admin", user.getUserName());
+ }
+
+ @Test
+ public void testLoginSucess() throws Exception {
+ User user = userService.findUserByUserName("admin");
+ user.setLastIp("127.0.0.1");
+ user.setLastVistit(new Date());
+ userService.loginSucess(user);
+ }
+}
\ No newline at end of file
diff --git a/spring-bbs-demo/src/main/webapp/WEB-INF/jsp/login.jsp b/spring-bbs-demo/src/main/webapp/WEB-INF/jsp/login.jsp
new file mode 100644
index 0000000..42a63f7
--- /dev/null
+++ b/spring-bbs-demo/src/main/webapp/WEB-INF/jsp/login.jsp
@@ -0,0 +1,30 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%--
+ Created by IntelliJ IDEA.
+ User: junqiangshen
+ Date: 15-9-16
+ Time: 下午11:38
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+ Spring样例演示论坛登陆界面
+
+
+
+
+
+
+ " method="post">
+ 用户名:
+
+
+ 密码:
+
+
+
+
+
+
+
diff --git a/spring-bbs-demo/src/main/webapp/WEB-INF/jsp/main.jsp b/spring-bbs-demo/src/main/webapp/WEB-INF/jsp/main.jsp
new file mode 100644
index 0000000..5bba758
--- /dev/null
+++ b/spring-bbs-demo/src/main/webapp/WEB-INF/jsp/main.jsp
@@ -0,0 +1,17 @@
+<%--
+ Created by IntelliJ IDEA.
+ User: junqiangshen
+ Date: 15-9-16
+ Time: 下午11:38
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+ Spring 测试论坛
+
+
+ ${user.userName},欢迎进入Spring 样例论坛,您当前积分为${user.credits};
+
+
diff --git a/spring-bbs-demo/src/main/webapp/WEB-INF/springbbs-servlet.xml b/spring-bbs-demo/src/main/webapp/WEB-INF/springbbs-servlet.xml
new file mode 100644
index 0000000..0aa1383
--- /dev/null
+++ b/spring-bbs-demo/src/main/webapp/WEB-INF/springbbs-servlet.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-bbs-demo/src/main/webapp/WEB-INF/web.xml b/spring-bbs-demo/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..c1637e6
--- /dev/null
+++ b/spring-bbs-demo/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+ contextConfigLocation
+ classpath:applicationContext.xml
+
+
+
+
+ org.springframework.web.context.ContextLoaderListener
+
+
+
+
+ springbbs
+ org.springframework.web.servlet.DispatcherServlet
+ 2
+
+
+
+ springbbs
+ *.html
+
+
+ Archetype Created Web Application
+
diff --git a/spring-bbs-demo/src/main/webapp/index.jsp b/spring-bbs-demo/src/main/webapp/index.jsp
new file mode 100644
index 0000000..4d05d28
--- /dev/null
+++ b/spring-bbs-demo/src/main/webapp/index.jsp
@@ -0,0 +1,5 @@
+
+
+Hello World test!
+
+
diff --git a/src/main/java/com/learn/note/practice/App.java b/src/main/java/com/learn/note/practice/App.java
deleted file mode 100644
index 25057b4..0000000
--- a/src/main/java/com/learn/note/practice/App.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.learn.note.practice;
-
-/**
- * Hello world!
- *
- */
-public class App
-{
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
-}
diff --git a/src/test/java/com/learn/note/practice/AppTest.java b/src/test/java/com/learn/note/practice/AppTest.java
deleted file mode 100644
index 51a391d..0000000
--- a/src/test/java/com/learn/note/practice/AppTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.learn.note.practice;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-}