Skip to content

Commit fa08a1f

Browse files
committed
demo of spring boot and MyBatis
0 parents  commit fa08a1f

15 files changed

+417
-0
lines changed

mybatis-demo.iml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="Spring" name="Spring">
5+
<configuration />
6+
</facet>
7+
<facet type="web" name="Web">
8+
<configuration>
9+
<webroots>
10+
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
11+
</webroots>
12+
<sourceRoots>
13+
<root url="file://$MODULE_DIR$/src/main/java" />
14+
<root url="file://$MODULE_DIR$/src/main/resources" />
15+
</sourceRoots>
16+
</configuration>
17+
</facet>
18+
</component>
19+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
20+
<output url="file://$MODULE_DIR$/target/classes" />
21+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
22+
<content url="file://$MODULE_DIR$">
23+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
24+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
25+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
26+
<excludeFolder url="file://$MODULE_DIR$/target" />
27+
</content>
28+
<orderEntry type="inheritedJdk" />
29+
<orderEntry type="sourceFolder" forTests="false" />
30+
<orderEntry type="library" name="Maven: org.activiti:activiti-spring-boot-starter-basic:5.19.0.2" level="project" />
31+
<orderEntry type="library" name="Maven: org.activiti:activiti-engine:5.19.0.2" level="project" />
32+
<orderEntry type="library" name="Maven: org.activiti:activiti-bpmn-converter:5.19.0.2" level="project" />
33+
<orderEntry type="library" name="Maven: org.activiti:activiti-bpmn-model:5.19.0.2" level="project" />
34+
<orderEntry type="library" name="Maven: org.activiti:activiti-process-validation:5.19.0.2" level="project" />
35+
<orderEntry type="library" name="Maven: org.activiti:activiti-image-generator:5.19.0.2" level="project" />
36+
<orderEntry type="library" name="Maven: org.apache.commons:commons-email:1.4" level="project" />
37+
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.3.2" level="project" />
38+
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.3.0" level="project" />
39+
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.4.RELEASE" level="project" />
40+
<orderEntry type="library" name="Maven: joda-time:joda-time:2.8.2" level="project" />
41+
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
42+
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.13" level="project" />
43+
<orderEntry type="library" name="Maven: org.activiti:activiti-spring:5.19.0.2" level="project" />
44+
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.4.RELEASE" level="project" />
45+
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.2.4.RELEASE" level="project" />
46+
<orderEntry type="library" name="Maven: org.springframework:spring-orm:4.2.4.RELEASE" level="project" />
47+
<orderEntry type="library" name="Maven: commons-dbcp:commons-dbcp:1.4" level="project" />
48+
<orderEntry type="library" name="Maven: commons-pool:commons-pool:1.6" level="project" />
49+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-actuator:1.3.2.RELEASE" level="project" />
50+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.3.2.RELEASE" level="project" />
51+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:1.3.2.RELEASE" level="project" />
52+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.3.2.RELEASE" level="project" />
53+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.3.2.RELEASE" level="project" />
54+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.3" level="project" />
55+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.3" level="project" />
56+
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.13" level="project" />
57+
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.13" level="project" />
58+
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.16" level="project" />
59+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator:1.3.2.RELEASE" level="project" />
60+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:1.3.2.RELEASE" level="project" />
61+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:1.3.2.RELEASE" level="project" />
62+
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.4.RELEASE" level="project" />
63+
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
64+
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.8" level="project" />
65+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-entitymanager:4.3.11.Final" level="project" />
66+
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
67+
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging-annotations:1.2.0.Beta1" level="project" />
68+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:4.3.11.Final" level="project" />
69+
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
70+
<orderEntry type="library" name="Maven: org.jboss:jandex:1.1.0.Final" level="project" />
71+
<orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
72+
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
73+
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:4.0.5.Final" level="project" />
74+
<orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" />
75+
<orderEntry type="library" name="Maven: org.javassist:javassist:3.18.1-GA" level="project" />
76+
<orderEntry type="library" name="Maven: javax.transaction:javax.transaction-api:1.2" level="project" />
77+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:1.9.2.RELEASE" level="project" />
78+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.11.2.RELEASE" level="project" />
79+
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:4.2.4.RELEASE" level="project" />
80+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-freemarker:1.3.2.RELEASE" level="project" />
81+
<orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.23" level="project" />
82+
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:4.2.4.RELEASE" level="project" />
83+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:1.3.2.RELEASE" level="project" />
84+
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jdbc:8.0.30" level="project" />
85+
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-juli:8.0.30" level="project" />
86+
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.2.4.RELEASE" level="project" />
87+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-remote-shell:1.3.2.RELEASE" level="project" />
88+
<orderEntry type="library" name="Maven: org.crashub:crash.cli:1.3.2" level="project" />
89+
<orderEntry type="library" name="Maven: org.crashub:crash.connectors.ssh:1.3.2" level="project" />
90+
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-core:0.11.0" level="project" />
91+
<orderEntry type="library" name="Maven: org.apache.sshd:sshd-pam:0.11.0" level="project" />
92+
<orderEntry type="library" name="Maven: net.sf.jpam:jpam:1.1" level="project" />
93+
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.51" level="project" />
94+
<orderEntry type="library" name="Maven: org.bouncycastle:bcpkix-jdk15on:1.51" level="project" />
95+
<orderEntry type="library" name="Maven: org.apache.mina:mina-core:2.0.7" level="project" />
96+
<orderEntry type="library" name="Maven: org.crashub:crash.embed.spring:1.3.2" level="project" />
97+
<orderEntry type="library" name="Maven: org.crashub:crash.plugins.cron:1.3.2" level="project" />
98+
<orderEntry type="library" name="Maven: it.sauronsoftware.cron4j:cron4j:2.2.5" level="project" />
99+
<orderEntry type="library" name="Maven: org.crashub:crash.plugins.mail:1.3.2" level="project" />
100+
<orderEntry type="library" name="Maven: org.crashub:crash.shell:1.3.2" level="project" />
101+
<orderEntry type="library" name="Maven: org.codehaus.groovy:groovy:2.4.4" level="project" />
102+
<orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.5.5" level="project" />
103+
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
104+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:1.3.2.RELEASE" level="project" />
105+
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf-spring4:2.1.4.RELEASE" level="project" />
106+
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf:2.1.4.RELEASE" level="project" />
107+
<orderEntry type="library" name="Maven: ognl:ognl:3.0.8" level="project" />
108+
<orderEntry type="library" name="Maven: org.unbescape:unbescape:1.1.0.RELEASE" level="project" />
109+
<orderEntry type="library" name="Maven: nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:1.3.1" level="project" />
110+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:1.3.2.RELEASE" level="project" />
111+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.3.2.RELEASE" level="project" />
112+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.0.30" level="project" />
113+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.0.30" level="project" />
114+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.30" level="project" />
115+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.0.30" level="project" />
116+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:1.3.2.RELEASE" level="project" />
117+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.2.2.Final" level="project" />
118+
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
119+
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.1.0" level="project" />
120+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.6.5" level="project" />
121+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.6.5" level="project" />
122+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.6.5" level="project" />
123+
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.4.RELEASE" level="project" />
124+
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.2.4.RELEASE" level="project" />
125+
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.4.RELEASE" level="project" />
126+
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.0.0" level="project" />
127+
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.0.0" level="project" />
128+
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.2.3" level="project" />
129+
<orderEntry type="library" scope="RUNTIME" name="Maven: com.h2database:h2:1.4.190" level="project" />
130+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:1.3.2.RELEASE" level="project" />
131+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
132+
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:1.10.19" level="project" />
133+
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.1" level="project" />
134+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
135+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
136+
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.4.RELEASE" level="project" />
137+
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.2.4.RELEASE" level="project" />
138+
</component>
139+
</module>

pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>mybatis-boot</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>war</packaging>
10+
11+
<name>mybatis-boot-demo</name>
12+
<description>Demo project for Spring Boot and Mybatis</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.3.2.RELEASE</version>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<java.version>1.8</java.version>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.activiti</groupId>
28+
<artifactId>activiti-spring-boot-starter-basic</artifactId>
29+
<version>5.19.0.2</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-actuator</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-data-jpa</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-freemarker</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-jdbc</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-remote-shell</artifactId>
50+
</dependency>
51+
<!--<dependency>-->
52+
<!--<groupId>org.springframework.boot</groupId>-->
53+
<!--<artifactId>spring-boot-starter-security</artifactId>-->
54+
<!--</dependency>-->
55+
<dependency>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-starter-web</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.mybatis.spring.boot</groupId>
65+
<artifactId>mybatis-spring-boot-starter</artifactId>
66+
<version>1.0.0</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>com.h2database</groupId>
70+
<artifactId>h2</artifactId>
71+
<scope>runtime</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-test</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
</dependencies>
79+
80+
<build>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.springframework.boot</groupId>
84+
<artifactId>spring-boot-maven-plugin</artifactId>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
89+
90+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class MybatisBootDemoApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(MybatisBootDemoApplication.class, args);
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example;
2+
3+
import org.springframework.boot.builder.SpringApplicationBuilder;
4+
import org.springframework.boot.context.web.SpringBootServletInitializer;
5+
6+
public class ServletInitializer extends SpringBootServletInitializer {
7+
8+
@Override
9+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10+
return application.sources(MybatisBootDemoApplication.class);
11+
}
12+
13+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.example.domain;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Created by qiuzhanghua on 16/2/24.
7+
*/
8+
public class City implements Serializable {
9+
10+
private Long id;
11+
12+
private String name;
13+
14+
private String state;
15+
16+
private String country;
17+
18+
public Long getId() {
19+
return this.id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getName() {
27+
return this.name;
28+
}
29+
30+
public void setName(String name) {
31+
this.name = name;
32+
}
33+
34+
public String getState() {
35+
return this.state;
36+
}
37+
38+
public void setState(String state) {
39+
this.state = state;
40+
}
41+
42+
public String getCountry() {
43+
return this.country;
44+
}
45+
46+
public void setCountry(String country) {
47+
this.country = country;
48+
}
49+
50+
@Override
51+
public String toString() {
52+
return "City{" +
53+
"id=" + this.id +
54+
", name='" + this.name + '\'' +
55+
", state='" + this.state + '\'' +
56+
", country='" + this.country + '\'' +
57+
'}';
58+
}
59+
}
60+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.mapper;
2+
3+
import com.example.domain.City;
4+
import org.mybatis.spring.SqlSessionTemplate;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
7+
8+
/**
9+
* Created by qiuzhanghua on 16/2/24.
10+
*/
11+
@Component
12+
public class CityMapper {
13+
14+
@Autowired
15+
private SqlSessionTemplate sqlSessionTemplate;
16+
17+
public City selectCityById(long id) {
18+
return this.sqlSessionTemplate.selectOne("selectCityById", id);
19+
}
20+
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.example.web;
2+
3+
import com.example.mapper.CityMapper;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.core.env.SystemEnvironmentPropertySource;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
9+
/**
10+
* Created by qiuzhanghua on 16/2/24.
11+
*/
12+
@Controller
13+
@RequestMapping(value="/")
14+
public class HomeController {
15+
16+
@Autowired
17+
private CityMapper cityMapper;
18+
19+
@RequestMapping(value="")
20+
String index() {
21+
System.out.println("+++++++++++++++++++++++++++++++++");
22+
System.out.println(this.cityMapper.selectCityById(1));
23+
System.out.println("+++++++++++++++++++++++++++++++++");
24+
return "index";
25+
}
26+
27+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.datasource.schema=import.sql
2+
mybatis.config=classpath:/mybatis-config.xml

src/main/resources/import.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE TABLE CITY (ID INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR, STATE VARCHAR, COUNTRY VARCHAR);
2+
3+
INSERT INTO CITY (NAME, STATE, COUNTRY) VALUES ('SAN FRANCISCO', 'CA', 'US');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE mapper
3+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5+
<mapper namespace="mapper.CityMapper">
6+
<select id="selectCityById" resultType="City">
7+
select * from City where id = #{id}
8+
</select>
9+
</mapper>

0 commit comments

Comments
 (0)