diff --git a/spring-boot-13-MyBatis/README.md b/spring-boot-13-MyBatis/README.md
index 77bbf6d..1901959 100644
--- a/spring-boot-13-MyBatis/README.md
+++ b/spring-boot-13-MyBatis/README.md
@@ -1,77 +1,22 @@
----
-## [spring-boot-3-logs-Logback 集成Logback日志框架](https://github.com/timebusker/spring-boot/tree/master/spring-boot-3-logs/spring-boot-3-logs-Logback/)
+## [集成MyBatis持久层框架](https://github.com/timebusker/spring-boot/tree/master/spring-boot-13-MyBatis/)
-### 项目阐述
+### 关于MyBatis

+ #### SLF4J+Logback配置说明
- * [logback日志分开纪录](http://www.cnblogs.com/DeepLearing/p/5664941.html)
+ * [logback日志分开纪录](http://www.cnblogs.com/DeepLearing/p/5664941.html)
* [logback节点配置详解](http://www.cnblogs.com/DeepLearing/p/5663178.html)
* [logback 中文手册.pdf](https://github.com/timebusker/spring-boot/raw/master/static/spring-boot-3-logs/spring-boot-3-logs-Logback/logback_cn.pdf?raw=true)
+ #### 配置多环境不同日志级别
***logback.xml*配置讲解**
```xml
-
-
-
-
-
-
-
-
-
-
-
-
- %date [%thread] %-5level %logger{80} || %msg%n
-
-
-
-
-
-
-
+```
-
-
-
-
-
- ${TEST_FILE_PATH}
-
-
- ${TEST_FILE_PATH}/info.%d{yyyy-MM-dd}.log
-
- 100
-
-
- ${PATTERN}
-
-
-
-
-
-
+### 相关文章
+
+[MyBatis Generator 详解](http://blog.csdn.net/isea533/article/details/42102297)
-
-
-
- ${PRO_FILE_PATH}
-
- ${PRO_FILE_PATH}/warn.%d{yyyy-MM-dd}.log
- 100
-
-
- ${PATTERN}
-
-
-
-
-
-
-
-```
-
----
\ No newline at end of file
diff --git a/spring-boot-13-MyBatis/pom.xml b/spring-boot-13-MyBatis/pom.xml
index 553d460..42231de 100644
--- a/spring-boot-13-MyBatis/pom.xml
+++ b/spring-boot-13-MyBatis/pom.xml
@@ -1,5 +1,6 @@
-
+
4.0.0
cn.timebusker
@@ -13,7 +14,7 @@
UTF-8
-
+
org.springframework.boot
@@ -56,8 +57,21 @@
true
+
+
+ mysql
+ mysql-connector-java
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 1.3.0
+
+
+
-
+
org.slf4j
slf4j-api
@@ -88,5 +102,10 @@
logback-core
+
+
+ com.alibaba
+ fastjson
+
diff --git a/spring-boot-13-MyBatis/src/main/java/cn/timebusker/App.java b/spring-boot-13-MyBatis/src/main/java/cn/timebusker/App.java
index 8b1f6c1..b2e2720 100644
--- a/spring-boot-13-MyBatis/src/main/java/cn/timebusker/App.java
+++ b/spring-boot-13-MyBatis/src/main/java/cn/timebusker/App.java
@@ -31,6 +31,7 @@ public class App {
* @ComponentScan 告诉Spring寻找其他组件,配置,以及业务层类,最前面才能加载到所有的类。
*/
+ @SuppressWarnings("unused")
public static void main(String[] args) {
// devtools:是spring boot的一个热部署工具
//设置 spring.devtools.restart.enabled 属性为false,可以关闭该特性.
@@ -42,7 +43,7 @@ public static void main(String[] args) {
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
- System.out.println(beanName);
+ // System.out.println(beanName);
}
}
}
diff --git a/spring-boot-13-MyBatis/src/main/java/cn/timebusker/dao/UserInfoMapper.java b/spring-boot-13-MyBatis/src/main/java/cn/timebusker/dao/UserInfoMapper.java
new file mode 100644
index 0000000..0222fd0
--- /dev/null
+++ b/spring-boot-13-MyBatis/src/main/java/cn/timebusker/dao/UserInfoMapper.java
@@ -0,0 +1,38 @@
+package cn.timebusker.dao;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+
+import cn.timebusker.entity.UserInfo;
+
+/**
+ * 基于注解实现持久化操作
+ *
+ */
+@Mapper
+public interface UserInfoMapper {
+
+ @Select("SELECT * FROM user_info WHERE username = #{name}")
+ List findByName(@Param("name") String name);
+
+ @Select("SELECT * FROM user_info WHERE id = #{id}")
+ List findById(@Param("id") int id);
+
+ @Insert("INSERT INTO user_info(Id,username,password,usertype,enabled,realname,email,tel) VALUES(#{id}, #{username},#{password}, #{usertype},#{enabled}, #{realname},#{email}, #{tel})")
+ int insert(UserInfo ui);
+
+ @Select("SELECT * FROM user_info WHERE 1=1 ")
+ List findAll();
+
+ @Update("UPDATE user_info SET password=#{password} WHERE username=#{username}")
+ void update(UserInfo ui);
+
+ @Delete("DELETE FROM user_info WHERE id =#{id}")
+ void delete(int id);
+}
\ No newline at end of file
diff --git a/spring-boot-13-MyBatis/src/main/java/cn/timebusker/entity/UserInfo.java b/spring-boot-13-MyBatis/src/main/java/cn/timebusker/entity/UserInfo.java
new file mode 100644
index 0000000..0883686
--- /dev/null
+++ b/spring-boot-13-MyBatis/src/main/java/cn/timebusker/entity/UserInfo.java
@@ -0,0 +1,101 @@
+package cn.timebusker.entity;
+
+import java.io.Serializable;
+
+/**
+ * 用户信息
+ */
+public class UserInfo implements Serializable {
+
+ private static final long serialVersionUID = -3054513298829319801L;
+
+ private Integer id;
+
+ private String username;
+
+ private String password;
+
+ private String usertype;
+
+ private Integer enabled;
+
+ private String realname;
+
+ private String qq;
+
+ private String email;
+
+ private String tel;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ 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 String getUsertype() {
+ return usertype;
+ }
+
+ public void setUsertype(String usertype) {
+ this.usertype = usertype;
+ }
+
+ public Integer getEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(Integer enabled) {
+ this.enabled = enabled;
+ }
+
+ public String getRealname() {
+ return realname;
+ }
+
+ public void setRealname(String realname) {
+ this.realname = realname;
+ }
+
+ public String getQq() {
+ return qq;
+ }
+
+ public void setQq(String qq) {
+ this.qq = qq;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getTel() {
+ return tel;
+ }
+
+ public void setTel(String tel) {
+ this.tel = tel;
+ }
+}
diff --git a/spring-boot-13-MyBatis/src/main/resources/application-dev.properties b/spring-boot-13-MyBatis/src/main/resources/application-dev.properties
index d4eecd1..e5b70e3 100644
--- a/spring-boot-13-MyBatis/src/main/resources/application-dev.properties
+++ b/spring-boot-13-MyBatis/src/main/resources/application-dev.properties
@@ -1,5 +1,5 @@
# 项目contextPath,一般在正式发布版本中,我们不配置
-server.context-path=/logback
+server.context-path=/mybatis
# 错误页,指定发生错误时,跳转的URL。请查看BasicErrorController源码便知
server.error.path=/error
# 服务端口
@@ -7,4 +7,11 @@ server.port=80
# session最大超时时间(分钟),默认为30
server.session-timeout=60
# 该服务绑定IP地址,启动服务器时如本机不是该IP地址则抛出异常启动失败,只有特殊需求的情况下才配置
-# server.address=192.168.16.11
\ No newline at end of file
+# server.address=192.168.16.11
+
+
+# 数据连接配置
+spring.datasource.url=jdbc:mysql://localhost:3306/timebusker-spring
+spring.datasource.username=root
+spring.datasource.password=root
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
\ No newline at end of file
diff --git a/spring-boot-13-MyBatis/src/test/java/test/dao/UserInfoMapperTest.java b/spring-boot-13-MyBatis/src/test/java/test/dao/UserInfoMapperTest.java
new file mode 100644
index 0000000..2d5fe3e
--- /dev/null
+++ b/spring-boot-13-MyBatis/src/test/java/test/dao/UserInfoMapperTest.java
@@ -0,0 +1,70 @@
+package test.dao;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import cn.timebusker.App;
+import cn.timebusker.dao.UserInfoMapper;
+import cn.timebusker.entity.UserInfo;
+
+import com.alibaba.fastjson.JSON;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = App.class, webEnvironment = WebEnvironment.RANDOM_PORT)
+public class UserInfoMapperTest {
+
+ @Autowired
+ UserInfoMapper dao;
+
+ @Test
+ public void findAll() throws Exception {
+ List lui = dao.findAll();
+ System.out.println("\n\n\n\n\n");
+ System.out.println("输出结果:" + JSON.toJSONString(lui.get(0)));
+ System.out.println("输出结果:" + JSON.toJSONString(lui));
+ System.out.println("\n\n\n\n\n");
+ }
+
+ @Test
+ public void findByName() throws Exception {
+ List lui = dao.findByName("test2");
+ System.out.println("\n\n\n\n\n");
+ System.out.println("输出结果:" + lui.get(0).getPassword());
+ System.out.println("\n\n\n\n\n");
+ }
+
+ @Test
+ public void insert() throws Exception {
+ UserInfo ui = new UserInfo();
+ ui.setId(1);
+ ui.setUsername("余姣姣");
+ System.out.println("\n\n\n\n\n");
+ System.out.println("输出结果:" + dao.insert(ui));
+ System.out.println("\n\n\n\n\n");
+ }
+
+ @Test
+ public void update() throws Exception {
+ List lui = dao.findById(2);
+ lui.get(0).setPassword("wewrewz");
+ dao.update(lui.get(0));
+ lui = dao.findById(2);
+ System.out.println("\n\n\n\n\n");
+ System.out.println("输出结果:" + JSON.toJSONString(lui));
+ System.out.println("\n\n\n\n\n");
+ }
+
+ @Test
+ public void delete() throws Exception {
+ dao.delete(1);
+ System.out.println("\n\n\n\n\n");
+ System.out.println("输出结果:" + JSON.toJSONString(dao.findById(1)));
+ System.out.println("\n\n\n\n\n");
+ }
+}
\ No newline at end of file
diff --git a/spring-boot-4-Scheduled/README.md b/spring-boot-4-Scheduled/README.md
index 786a699..7a356b7 100644
--- a/spring-boot-4-Scheduled/README.md
+++ b/spring-boot-4-Scheduled/README.md
@@ -55,6 +55,12 @@
- #### Spring Task 简单使用、动态修改cron表达式、动态添加修改删除定时任务
++ 关于 spring task的注解使用--@Scheduled详解
+ - @Scheduled(fixedRate = 5000) :上一次开始执行时间点之后5秒再执行
+ - @Scheduled(fixedDelay = 5000) :上一次执行完毕时间点之后5秒再执行
+ - @Scheduled(initialDelay=1000, fixedRate=5000) :第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次
+ - @Scheduled(cron="*/5 * * * * *") :通过cron表达式定义规则
+
+ 使用spring task不需要引用额外的jar包,spring-core中已经完成封装

@@ -93,4 +99,8 @@ public class SpringTaskSample {

+ Spring的Scheduled Task实现集群思路
- 实现任务互斥,通过声明***全局锁***作为互斥变量,获得锁的变量才有权执行任务。
\ No newline at end of file
+实现任务互斥,通过声明 **全局锁** 作为互斥变量,获得锁的变量才有权执行任务。
+
+
+
+
\ No newline at end of file