From d0b3d31eef54b0118167493600f3e83ec11dd41a Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Mon, 13 Nov 2017 21:18:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20mybatis-demo=20=E7=9A=84?= =?UTF-8?q?=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-boot-demo-mybatis/README.md | 181 +++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 spring-boot-demo-mybatis/README.md diff --git a/spring-boot-demo-mybatis/README.md b/spring-boot-demo-mybatis/README.md new file mode 100644 index 0000000..a65e971 --- /dev/null +++ b/spring-boot-demo-mybatis/README.md @@ -0,0 +1,181 @@ +# spring-boot-demo-mybatis + +依赖 [spring-boot-demo-helloworld](../spring-boot-demo-parent) + +### pom.xml + +```xml + + + 4.0.0 + + spring-boot-demo-mybatis + 0.0.1-SNAPSHOT + war + + spring-boot-demo-mybatis + Demo project for Spring Boot + + + com.xkcoding + spring-boot-demo-parent + 0.0.1-SNAPSHOT + ../spring-boot-demo-parent/pom.xml + + + + 1.3.1 + 1.1.5 + 1.1.1 + 1.1.0 + + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis.starter.version} + + + + com.alibaba + druid-spring-boot-starter + ${druid.starter.version} + + + + tk.mybatis + mapper-spring-boot-starter + ${mapper.version} + + + + com.github.pagehelper + pagehelper-spring-boot-starter + ${pagehelper.version} + + + + + spring-boot-demo-mybatis + + + +``` + +### application.yml + +```yml +server: + port: 8080 + context-path: /demo +spring: + jackson: + default-property-inclusion: non_null + datasource: + # 启动时自动运行的 SQL 文件 + schema: classpath:init-sql/schema.sql + continue-on-error: true + druid: + url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false + username: root + password: root + driver-class-name: com.mysql.jdbc.Driver + # 连接池配置 + # 初始化大小,最小,最大 + initialSize: 5 + minIdle: 5 + maxActive: 20 + # 配置获取连接等待超时的时间 + maxWait: 60000 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + timeBetweenEvictionRunsMillis: 60000 + # 配置一个连接在池中最小生存的时间,单位是毫秒 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 FROM DUAL + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + # 打开PSCache,并且指定每个连接上PSCache的大小 + poolPreparedStatements: true + maxPoolPreparedStatementPerConnectionSize: 20 + # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + filters: stat,wall,log4j + # 监控配置 + web-stat-filter: + enabled: true + url-pattern: /* + exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" + stat-view-servlet: + enabled: true + url-pattern: /sys/druid/* + reset-enable: fasle + login-username: xkcoding + login-password: 123456 + filter: + stat: + log-slow-sql: true + slow-sql-millis: 5000 + merge-sql: true +# mybatis 配置 +mybatis: + type-aliases-package: com.xkcoding.springbootdemomybatis.model + mapper-locations: classpath:mapper/*.xml + # 配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性 + configuration: + map-underscore-to-camel-case: true +# 通用 Mapper 配置 +mapper: + not-empty: false + identity: MYSQL + mappers: com.xkcoding.springbootdemomybatis.util.MyMapper +# PageHelper 配置 +pagehelper: + helper-dialect: mysql + reasonable: true + support-methods-arguments: true + params: count=countSql +``` + +### SpringBootDemoMybatisApplication.java + +```java +@SpringBootApplication +@MapperScan(basePackages = {"com.xkcoding.springbootdemomybatis.mapper"}) +public class SpringBootDemoMybatisApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoMybatisApplication.class, args); + } +} +``` + +### schema.sql + +```sql +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for `boot_user` +-- ---------------------------- +DROP TABLE IF EXISTS `mybatis_user`; +CREATE TABLE `mybatis_user` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(32) DEFAULT NULL, + `tel` varchar(11) DEFAULT NULL, + `create_time` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Records of boot_user +-- ---------------------------- +INSERT INTO `mybatis_user` VALUES (1, 'klay', '13799008800', '2017-11-13 16:04:39'); +INSERT INTO `mybatis_user` VALUES (2, 'Tome', '18988991234', '2017-11-13 16:13:28'); +``` + +### 其余代码 + +详情请参见本demo。 \ No newline at end of file