Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
happyxiaofan
committed
Sep 12, 2017
1 parent
7aecdf2
commit 8b45b1a
Showing
14 changed files
with
1,453 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE `user` ( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增,主键', | ||
`user_id` bigint(20) DEFAULT NULL COMMENT '用户id', | ||
`user_name` varchar(15) DEFAULT NULL, | ||
`age` int(11) DEFAULT NULL COMMENT '年龄', | ||
`birth` date DEFAULT NULL COMMENT '生日', | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `id_UNIQUE` (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='用户信息表'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>spring-boot-learning-examples</artifactId> | ||
<groupId>com.rhwayfun</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-mybatis</artifactId> | ||
<parent> | ||
<artifactId>spring-boot-learning-examples</artifactId> | ||
<groupId>com.rhwayfun</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-boot-mybatis</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
</project> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mybatis.spring.boot</groupId> | ||
<artifactId>mybatis-spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
spring-boot-mybatis/src/main/java/com/rhwayfun/springboot/mybatis/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.rhwayfun.springboot.mybatis; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
SpringApplication.run(Application.class, args); | ||
Thread.sleep(Long.MAX_VALUE); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...g-boot-mybatis/src/main/java/com/rhwayfun/springboot/mybatis/config/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.rhwayfun.springboot.mybatis.config; | ||
|
||
import com.alibaba.druid.pool.DruidDataSource; | ||
import com.rhwayfun.springboot.mybatis.constants.DataSourceConstants; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "mybatis.datasource") | ||
@MapperScan(basePackages = { DataSourceConstants.MAPPER_PACKAGE }, sqlSessionFactoryRef = "mybatisSqlSessionFactory") | ||
public class DataSourceConfig { | ||
|
||
private String url; | ||
|
||
private String username; | ||
|
||
private String password; | ||
|
||
@Bean(name = "mybatisDataSource") | ||
public DataSource mybatisDataSource() { | ||
DruidDataSource dataSource = new DruidDataSource(); | ||
dataSource.setDriverClassName("com.mysql.jdbc.Driver"); | ||
dataSource.setUrl(url); | ||
dataSource.setUsername(username); | ||
dataSource.setPassword(password); | ||
return dataSource; | ||
} | ||
|
||
@Bean(name = "mybatisTransactionManager") | ||
public DataSourceTransactionManager mybatisTransactionManager() { | ||
return new DataSourceTransactionManager(mybatisDataSource()); | ||
} | ||
|
||
@Bean(name = "mybatisSqlSessionFactory") | ||
public SqlSessionFactory mybatisSqlSessionFactory(@Qualifier("mybatisDataSource") DataSource mybatisDataSource) | ||
throws Exception { | ||
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); | ||
sessionFactory.setDataSource(mybatisDataSource); | ||
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver() | ||
.getResources(DataSourceConstants.MAPPER_LOCATION)); | ||
return sessionFactory.getObject(); | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
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; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...-mybatis/src/main/java/com/rhwayfun/springboot/mybatis/constants/DataSourceConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.rhwayfun.springboot.mybatis.constants; | ||
|
||
public abstract class DataSourceConstants { | ||
|
||
public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.mybatis.mapper"; | ||
public static final String MAPPER_LOCATION = "classpath:mybatis/*Mapper*.xml"; | ||
|
||
} |
179 changes: 179 additions & 0 deletions
179
spring-boot-mybatis/src/main/java/com/rhwayfun/springboot/mybatis/entity/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package com.rhwayfun.springboot.mybatis.entity; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
public class User implements Serializable { | ||
/** | ||
* | ||
* This field was generated by MyBatis Generator. | ||
* This field corresponds to the database column user.id | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
private Integer id; | ||
|
||
/** | ||
* | ||
* This field was generated by MyBatis Generator. | ||
* This field corresponds to the database column user.user_id | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
private Long userId; | ||
|
||
/** | ||
* | ||
* This field was generated by MyBatis Generator. | ||
* This field corresponds to the database column user.user_name | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
private String userName; | ||
|
||
/** | ||
* | ||
* This field was generated by MyBatis Generator. | ||
* This field corresponds to the database column user.age | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
private Integer age; | ||
|
||
/** | ||
* | ||
* This field was generated by MyBatis Generator. | ||
* This field corresponds to the database column user.birth | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
private Date birth; | ||
|
||
/** | ||
* This field was generated by MyBatis Generator. | ||
* This field corresponds to the database table user | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method returns the value of the database column user.id | ||
* | ||
* @return the value of user.id | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method sets the value of the database column user.id | ||
* | ||
* @param id the value for user.id | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method returns the value of the database column user.user_id | ||
* | ||
* @return the value of user.user_id | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public Long getUserId() { | ||
return userId; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method sets the value of the database column user.user_id | ||
* | ||
* @param userId the value for user.user_id | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public void setUserId(Long userId) { | ||
this.userId = userId; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method returns the value of the database column user.user_name | ||
* | ||
* @return the value of user.user_name | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public String getUserName() { | ||
return userName; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method sets the value of the database column user.user_name | ||
* | ||
* @param userName the value for user.user_name | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public void setUserName(String userName) { | ||
this.userName = userName == null ? null : userName.trim(); | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method returns the value of the database column user.age | ||
* | ||
* @return the value of user.age | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method sets the value of the database column user.age | ||
* | ||
* @param age the value for user.age | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public void setAge(Integer age) { | ||
this.age = age; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method returns the value of the database column user.birth | ||
* | ||
* @return the value of user.birth | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public Date getBirth() { | ||
return birth; | ||
} | ||
|
||
/** | ||
* This method was generated by MyBatis Generator. | ||
* This method sets the value of the database column user.birth | ||
* | ||
* @param birth the value for user.birth | ||
* | ||
* @mbg.generated Tue Sep 12 20:40:14 CST 2017 | ||
*/ | ||
public void setBirth(Date birth) { | ||
this.birth = birth; | ||
} | ||
} |
Oops, something went wrong.