├── .gitignore
├── README.md
├── pom.xml
├── spring-boot-mybatis-parent
└── pom.xml
├── spring-boot-mybatis-sample
├── pom.xml
├── spring-boot-mybatis-sample-default
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── sample
│ │ │ │ └── springboot
│ │ │ │ └── mybatis
│ │ │ │ └── defaultconfig
│ │ │ │ ├── SampleApplication.java
│ │ │ │ ├── service
│ │ │ │ ├── Member.java
│ │ │ │ └── MemberMapper.java
│ │ │ │ └── web
│ │ │ │ └── MemberController.java
│ │ └── resources
│ │ │ ├── application.yml
│ │ │ ├── data.sql
│ │ │ └── schema.sql
│ │ └── test
│ │ └── java
│ │ └── sample
│ │ └── springboot
│ │ └── mybatis
│ │ └── defaultconfig
│ │ └── SpringDemoApplicationTests.java
├── spring-boot-mybatis-sample-groovy
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── sample
│ │ │ │ └── springboot
│ │ │ │ └── mybatis
│ │ │ │ └── groovymapper
│ │ │ │ ├── SampleApplication.java
│ │ │ │ ├── service
│ │ │ │ ├── Member.java
│ │ │ │ └── MemberMapper.groovy
│ │ │ │ └── web
│ │ │ │ └── MemberController.java
│ │ └── resources
│ │ │ ├── application.yml
│ │ │ ├── data.sql
│ │ │ └── schema.sql
│ │ └── test
│ │ └── java
│ │ └── sample
│ │ └── springboot
│ │ └── mybatis
│ │ └── groovymapper
│ │ └── SpringDemoApplicationTests.java
├── spring-boot-mybatis-sample-hybrid
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── sample
│ │ │ │ └── springboot
│ │ │ │ └── mybatis
│ │ │ │ └── hybrid
│ │ │ │ ├── SampleApplication.java
│ │ │ │ ├── service
│ │ │ │ ├── Member.java
│ │ │ │ ├── MemberAnnotationMapper.java
│ │ │ │ ├── MemberXmlMapper.java
│ │ │ │ └── mapper.xml
│ │ │ │ └── web
│ │ │ │ └── MemberController.java
│ │ └── resources
│ │ │ ├── application.yml
│ │ │ ├── data.sql
│ │ │ ├── mybatis-configuration.xml
│ │ │ └── schema.sql
│ │ └── test
│ │ └── java
│ │ └── sample
│ │ └── springboot
│ │ └── mybatis
│ │ └── hybrid
│ │ └── SpringDemoApplicationTests.java
├── spring-boot-mybatis-sample-simple
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── sample
│ │ │ │ └── springboot
│ │ │ │ └── mybatis
│ │ │ │ └── defaultconfig
│ │ │ │ └── SampleApplication.java
│ │ └── resources
│ │ │ ├── application.yml
│ │ │ ├── data.sql
│ │ │ └── schema.sql
│ │ └── test
│ │ └── java
│ │ └── sample
│ │ └── springboot
│ │ └── mybatis
│ │ └── defaultconfig
│ │ └── SpringDemoApplicationTests.java
└── spring-boot-mybatis-sample-xml
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── sample
│ │ │ └── springboot
│ │ │ └── mybatis
│ │ │ └── xmlconfig
│ │ │ ├── SampleApplication.java
│ │ │ ├── service
│ │ │ ├── Member.java
│ │ │ ├── MemberMapper.java
│ │ │ └── mapper.xml
│ │ │ └── web
│ │ │ └── MemberController.java
│ └── resources
│ │ ├── application.yml
│ │ ├── data.sql
│ │ └── schema.sql
│ └── test
│ └── java
│ └── sample
│ └── springboot
│ └── mybatis
│ └── xmlconfig
│ └── SpringDemoApplicationTests.java
└── spring-boot-mybatis
├── META-INF
└── spring.factories
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── springframework
│ │ └── boot
│ │ └── mybatis
│ │ └── autoconfigure
│ │ ├── Mapper.java
│ │ ├── MyBatisAutoConfiguration.java
│ │ ├── MyBatisConfigurer.java
│ │ ├── MyBatisConfigurerAdapter.java
│ │ ├── MyBatisMapperScannerRegistrar.java
│ │ ├── MyBatisProperties.java
│ │ └── SqlSessionFactoryUpdateConfigurationBean.java
└── resources
│ └── META-INF
│ └── spring.factories
└── test
└── java
└── org
└── sbcoba
└── mymodule
├── AppTest.java
└── TestClass.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | *.sw?
3 | .#*
4 | *#
5 | *~
6 | /build
7 | /code
8 | .classpath
9 | .project
10 | .settings
11 | .metadata
12 | .factorypath
13 | .recommenders
14 | bin
15 | build
16 | lib/
17 | target
18 | .factorypath
19 | .springBeans
20 | interpolated*.xml
21 | dependency-reduced-pom.xml
22 | build.log
23 | _site/
24 | .*.md.html
25 | manifest.yml
26 | MANIFEST.MF
27 | settings.xml
28 | activemq-data
29 | overridedb.*
30 | *.iml
31 | *.ipr
32 | *.iws
33 | .idea
34 | *.jar
35 | .DS_Store
36 | .factorypath
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spring Boot MyBatis
2 |
3 | ## 버전
4 | - Spring Boot 1.3.0.M5 기준
5 |
6 | ## 소개
7 | - Spring Boot Project 에서 기본적으로 MyBatis 지원되지 않기 때문에 만듦
8 | - 간단히 Dependency 추가로 인해 Spring Boot 에서 MyBatis를 사용할 수 있도록 지원
9 | - 기존의 xml 설정없이 모든 기능을 확장할 수 있도록 구현
10 |
11 | ## 실행조건
12 | - JDK 1.6 이상 환경 ( JDK 1.7 이상 추천 )
13 | - Maven 설치 (추후 Gradle 지원 예정)
14 | - Spring Boot 개발 환경
15 |
16 | ## 소스 내려받기
17 | ```sh
18 | $ git clone https://github.com/sbcoba/spring-boot-mybatis
19 | ```
20 |
21 | ## 샘플 실행
22 | ```sh
23 | $ cd spring-boot-mybatis
24 | $ mvn clean install
25 | # 샘플 실행
26 | $ cd ../spring-boot-mybatis-sample
27 | $ mvn -pl spring-boot-mybatis-sample-default spring-boot:run
28 | $ mvn -pl spring-boot-mybatis-sample-simple spring-boot:run
29 | $ mvn -pl spring-boot-mybatis-sample-xml spring-boot:run
30 | $ mvn -pl spring-boot-mybatis-sample-hybrid spring-boot:run
31 | $ mvn -pl spring-boot-mybatis-sample-groovy spring-boot:run
32 | ```
33 |
34 | ## Maven Dependency 설정
35 | ```xml
36 |
37 | org.springframework.boot.mybatis
38 | spring-boot-mybatis
39 | 1.3.0.BUILD-SNAPSHOT
40 |
41 | ```
42 |
43 | ## 예제설명
44 | - spring-boot-mybatis-sample-default
45 | - 기본적이 설정이 없을 때 작동하는 예제
46 | - 기본적인 설정 Annotation을 사용
47 | - spring-boot-mybatis-sample-simple
48 | - 가장 간단하게 DB에 접근할 수 있도록 하나의 Class에서 작동하는 예제
49 | - spring-boot-mybatis-sample-xml
50 | - XML mapper를 사용하여 작동하는 예제
51 | - 기본적인 XML 설정 필요
52 | - spring-boot-mybatis-sample-hybrid
53 | - 기본 Annotation 형태와 XML형태를 동시에 사용하도록 작동하는 예제
54 | - 단지 테스트형태이며 실무에서는 지양필요
55 | - spring-boot-mybatis-sample-groovy
56 | - 기본 Annotation 형태는 XML형태에서 Multiline이 되지 않기 때문에 Groovy의 '''문자열''' 기능을 사용하여 멀티라인 문자열을 구현 하여 쿼리를 편리하게 작성할 수 있도록 구성된 예제
57 | - 이 부분은 Spring Boot MyBatis와 관계없이 작동하는 예제
58 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | org.springframework.boot
5 | spring-boot-mybatis-build
6 | 1.3.0.BUILD-SNAPSHOT
7 | pom
8 | spring-boot-mybatis-build
9 | Spring Boot Mybatis Build
10 | http://sbcoba.tistory.com
11 |
12 | Lee su hong
13 | http://sbcoba.tistory.com
14 |
15 |
16 |
17 | Apache License, Version 2.0
18 | http://www.apache.org/licenses/LICENSE-2.0
19 |
20 |
21 |
22 | https://github.com/sbcoba/spring-boot-mybatis
23 |
24 |
25 |
26 | sbcoba
27 | Lee su hong
28 | sbcoba at gmail.com
29 |
30 | Project lead
31 |
32 |
33 |
34 |
35 | 3.2.1
36 |
37 |
38 | ${basedir}
39 |
40 |
41 |
42 | default
43 |
44 | true
45 |
46 |
47 | spring-boot-mybatis-parent
48 | spring-boot-mybatis
49 | spring-boot-mybatis-sample
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-parent/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.springframework.boot
6 | spring-boot-starter-parent
7 | 1.3.0.M5
8 |
9 |
10 |
11 | org.springframework.boot.mybatis
12 | spring-boot-mybatis-parent
13 | 1.3.0.BUILD-SNAPSHOT
14 | pom
15 | spring-boot-mybatis-parent
16 |
17 | Spring Boot Mybatis
18 | http://github.io/sbcoba/spring-boot-mybatis/
19 |
20 | sbcoba
21 | http://sbcoba.tistoty.com
22 |
23 |
24 |
25 | UTF-8
26 |
27 |
28 |
29 |
30 |
31 | org.springframework.boot.mybatis
32 | spring-boot-mybatis
33 | ${project.version}
34 |
35 |
36 | org.mybatis
37 | mybatis
38 | 3.3.0
39 |
40 |
41 | org.mybatis
42 | mybatis-spring
43 | 1.2.3
44 |
45 |
46 |
47 |
48 |
49 |
50 | spring-snapshots
51 | Spring Snapshots
52 | https://repo.spring.io/snapshot
53 |
54 | true
55 |
56 |
57 |
58 | spring-milestones
59 | Spring Milestones
60 | https://repo.spring.io/milestone
61 |
62 | false
63 |
64 |
65 |
66 |
67 |
68 | spring-snapshots
69 | Spring Snapshots
70 | https://repo.spring.io/snapshot
71 |
72 | true
73 |
74 |
75 |
76 | spring-milestones
77 | Spring Milestones
78 | https://repo.spring.io/milestone
79 |
80 | false
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.springframework.boot.mybatis
6 | spring-boot-mybatis-parent
7 | 1.3.0.BUILD-SNAPSHOT
8 | ../spring-boot-mybatis-parent
9 |
10 |
11 | org.springframework.boot.mybatis
12 | spring-boot-mybatis-sample
13 | pom
14 | spring-boot-mybatis-sample
15 |
16 | Spring Boot Mybatis
17 | http://github.io/sbcoba/spring-boot-mybatis/
18 |
19 | sbcoba
20 | http://sbcoba.tistoty.com
21 |
22 |
23 |
24 | spring-boot-mybatis-sample-default
25 | spring-boot-mybatis-sample-simple
26 | spring-boot-mybatis-sample-xml
27 | spring-boot-mybatis-sample-hybrid
28 | spring-boot-mybatis-sample-groovy
29 |
30 |
31 |
32 | UTF-8
33 |
34 |
35 |
36 |
37 | spring-snapshots
38 | Spring Snapshots
39 | https://repo.spring.io/snapshot
40 |
41 | true
42 |
43 |
44 |
45 | spring-milestones
46 | Spring Milestones
47 | https://repo.spring.io/milestone
48 |
49 | false
50 |
51 |
52 |
53 |
54 |
55 | spring-snapshots
56 | Spring Snapshots
57 | https://repo.spring.io/snapshot
58 |
59 | true
60 |
61 |
62 |
63 | spring-milestones
64 | Spring Milestones
65 | https://repo.spring.io/milestone
66 |
67 | false
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot.mybatis
7 | spring-boot-mybatis-sample
8 | 1.3.0.BUILD-SNAPSHOT
9 | ../
10 |
11 |
12 | spring-boot-mybatis-sample-default
13 | war
14 |
15 | spring-boot-mybatis-sample-default
16 | Spring Boot MyBatis sample
17 |
18 |
19 | ${basedir}/../..
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.springframework.boot.mybatis
30 | spring-boot-mybatis
31 |
32 |
33 |
34 | com.h2database
35 | h2
36 | runtime
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-test
42 | test
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-maven-plugin
51 |
52 |
53 | org.apache.maven.plugins
54 | maven-surefire-plugin
55 |
56 | false
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/java/sample/springboot/mybatis/defaultconfig/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.defaultconfig;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SampleApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(SampleApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/java/sample/springboot/mybatis/defaultconfig/service/Member.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.defaultconfig.service;
2 |
3 | /**
4 | * Sample DTO
5 | *
6 | * @author sbcoba
7 | *
8 | */
9 | public class Member {
10 | private Long id;
11 | private String name;
12 | private String phone;
13 |
14 | public Long getId() {
15 | return id;
16 | }
17 | public void setId(Long id) {
18 | this.id = id;
19 | }
20 | public String getName() {
21 | return name;
22 | }
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 | public String getPhone() {
27 | return phone;
28 | }
29 | public void setPhone(String phone) {
30 | this.phone = phone;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "Member [id=" + id + ", name=" + name + ", phone=" + phone + "]";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/java/sample/springboot/mybatis/defaultconfig/service/MemberMapper.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.defaultconfig.service;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Select;
6 | import org.springframework.boot.mybatis.autoconfigure.Mapper;
7 |
8 | @Mapper
9 | public interface MemberMapper {
10 | @Select("SELECT ID, NAME, PHONE FROM MEMBER")
11 | List findAll();
12 |
13 | @Select("SELECT ID, NAME, PHONE FROM MEMBER WHERE ID = #{id}")
14 | Member findById(Long id);
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/java/sample/springboot/mybatis/defaultconfig/web/MemberController.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.defaultconfig.web;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import sample.springboot.mybatis.defaultconfig.service.Member;
11 | import sample.springboot.mybatis.defaultconfig.service.MemberMapper;
12 |
13 | @RestController
14 | public class MemberController {
15 |
16 | @Autowired
17 | MemberMapper memberMapper;
18 |
19 | @RequestMapping("members")
20 | public List members() {
21 | return memberMapper.findAll();
22 | }
23 |
24 | @RequestMapping("member/{id}")
25 | public Member member(@PathVariable("id") Long id) {
26 | return memberMapper.findById(id);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | h2:
3 | console:
4 | path: /console
5 | enabled: true
6 |
7 | logging:
8 | level:
9 | org.springframework.boot: DEBUG
10 | sample.springboot.mybatis: DEBUG
11 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/resources/data.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO MEMBER (ID, NAME, PHONE) VALUES (1, 'xml', '010-9912-1234');
2 | INSERT INTO MEMBER (ID, NAME, PHONE) VALUES (2, 'annotation', '010-2333-4321');
3 |
4 | INSERT INTO MEMBER_GROUP (ID, NAME, REMARK) VALUES (1, 'Team1', 'Test1 group');
5 | INSERT INTO MEMBER_GROUP (ID, NAME, REMARK) VALUES (2, 'Team2', 'Test2 group');
6 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE MEMBER (
2 | ID INT PRIMARY KEY,
3 | NAME VARCHAR(50),
4 | PHONE VARCHAR(20));
5 |
6 | CREATE TABLE MEMBER_GROUP (
7 | ID INT PRIMARY KEY,
8 | NAME VARCHAR(50),
9 | REMARK VARCHAR(20));
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-default/src/test/java/sample/springboot/mybatis/defaultconfig/SpringDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.defaultconfig;
2 |
3 | import static org.hamcrest.Matchers.*;
4 | import static org.junit.Assert.*;
5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
6 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
8 |
9 | import java.util.List;
10 |
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.boot.test.SpringApplicationConfiguration;
18 | import org.springframework.http.MediaType;
19 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20 | import org.springframework.test.context.web.WebAppConfiguration;
21 | import org.springframework.test.web.servlet.MockMvc;
22 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
23 | import org.springframework.web.context.WebApplicationContext;
24 |
25 | import sample.springboot.mybatis.defaultconfig.service.Member;
26 | import sample.springboot.mybatis.defaultconfig.service.MemberMapper;
27 | import sample.springboot.mybatis.defaultconfig.web.MemberController;
28 |
29 | @RunWith(SpringJUnit4ClassRunner.class)
30 | @SpringApplicationConfiguration(classes = SampleApplication.class)
31 | @WebAppConfiguration
32 | public class SpringDemoApplicationTests {
33 | private static final Logger log = LoggerFactory.getLogger(SpringDemoApplicationTests.class);
34 |
35 | @Autowired
36 | WebApplicationContext wac;
37 |
38 | MockMvc mockMvc;
39 |
40 | @Before
41 | public void init() {
42 | mockMvc = MockMvcBuilders.webAppContextSetup(wac)
43 | .alwaysDo(print())
44 | .build();
45 | }
46 |
47 | @Test
48 | public void controllerMemberTest() throws Exception {
49 | mockMvc.perform(
50 | get("/member/{id}", 1).accept(MediaType.APPLICATION_JSON))
51 | .andExpect(handler().handlerType(MemberController.class))
52 | .andExpect(handler().methodName("member"))
53 | .andExpect(status().isOk())
54 | .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
55 | );
56 | }
57 |
58 | @Autowired
59 | MemberMapper memberMapper;
60 |
61 | @Test
62 | public void findAllTest() {
63 | List members = memberMapper.findAll();
64 | log.debug("members : {}", members);
65 | assertThat(members.size(), is(2));
66 | }
67 |
68 | @Test
69 | public void findByIdTest() {
70 | Member member1 = memberMapper.findById(1L);
71 | log.debug("member1 : {}", member1);
72 | assertThat(member1.getId(), is(1L));
73 | assertThat(member1.getName(), is("xml"));
74 | assertThat(member1.getPhone(), is("010-9912-1234"));
75 |
76 | Member member2 = memberMapper.findById(2L);
77 | log.debug("member2 : {}", member2);
78 | assertThat(member2.getId(), is(2L));
79 | assertThat(member2.getName(), is("annotation"));
80 | assertThat(member2.getPhone(), is("010-2333-4321"));
81 |
82 | Member member3 = memberMapper.findById(3L);
83 | log.debug("member3 : {}", member3);
84 | assertThat(member3, is(nullValue()));
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /target/
3 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot.mybatis
7 | spring-boot-mybatis-sample
8 | 1.3.0.BUILD-SNAPSHOT
9 | ../
10 |
11 |
12 | spring-boot-mybatis-sample-groovy
13 | war
14 |
15 | spring-boot-mybatis-sample-groovy
16 | Spring Boot MyBatis sample
17 |
18 |
19 | ${basedir}/../..
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.springframework.boot.mybatis
30 | spring-boot-mybatis
31 |
32 |
33 |
34 | com.h2database
35 | h2
36 | runtime
37 |
38 |
39 |
40 | org.codehaus.groovy
41 | groovy-all
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-test
47 | test
48 |
49 |
50 |
51 |
52 |
53 |
54 | src/main/java
55 |
56 | **/*.java
57 | **/*.groovy
58 |
59 |
60 |
61 | src/main/resources
62 |
63 |
64 |
65 |
66 |
67 | org.springframework.boot
68 | spring-boot-maven-plugin
69 |
70 |
71 | org.apache.maven.plugins
72 | maven-surefire-plugin
73 |
74 | false
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-compiler-plugin
80 |
81 | groovy-eclipse-compiler
82 | true
83 | false
84 | false
85 |
86 |
87 |
88 | org.codehaus.groovy
89 | groovy-eclipse-compiler
90 | 2.9.1-01
91 |
92 |
93 | org.codehaus.groovy
94 | groovy-eclipse-batch
95 | 2.3.7-01
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/java/sample/springboot/mybatis/groovymapper/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.groovymapper;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import sample.springboot.mybatis.groovymapper.SampleApplication;
7 |
8 | @SpringBootApplication
9 | public class SampleApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(SampleApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/java/sample/springboot/mybatis/groovymapper/service/Member.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.groovymapper.service;
2 |
3 | /**
4 | * Sample DTO
5 | *
6 | * @author sbcoba
7 | *
8 | */
9 | public class Member {
10 | private Long id;
11 | private String name;
12 | private String phone;
13 |
14 | public Long getId() {
15 | return id;
16 | }
17 | public void setId(Long id) {
18 | this.id = id;
19 | }
20 | public String getName() {
21 | return name;
22 | }
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 | public String getPhone() {
27 | return phone;
28 | }
29 | public void setPhone(String phone) {
30 | this.phone = phone;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "Member [id=" + id + ", name=" + name + ", phone=" + phone + "]";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/java/sample/springboot/mybatis/groovymapper/service/MemberMapper.groovy:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.groovymapper.service;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Select;
6 | import org.springframework.boot.mybatis.autoconfigure.Mapper;
7 |
8 | @Mapper
9 | public interface MemberMapper {
10 |
11 | @Select("""
12 | SELECT ID,
13 | NAME,
14 | PHONE
15 | FROM MEMBER
16 | """)
17 | List findAll();
18 |
19 | @Select("""
20 | SELECT ID,
21 | NAME,
22 | PHONE
23 | FROM MEMBER
24 | WHERE ID = #{id}
25 | """)
26 | Member findById(Long id);
27 | }
28 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/java/sample/springboot/mybatis/groovymapper/web/MemberController.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.groovymapper.web;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import sample.springboot.mybatis.groovymapper.service.Member;
11 | import sample.springboot.mybatis.groovymapper.service.MemberMapper;
12 |
13 | @RestController
14 | public class MemberController {
15 |
16 | @Autowired
17 | MemberMapper memberMapper;
18 |
19 | @RequestMapping("members")
20 | public List members() {
21 | return memberMapper.findAll();
22 | }
23 |
24 | @RequestMapping("member/{id}")
25 | public Member member(@PathVariable("id") Long id) {
26 | return memberMapper.findById(id);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | h2:
3 | console:
4 | path: /console
5 | enabled: true
6 |
7 | logging:
8 | level:
9 | org.springframework.boot: DEBUG
10 | sample.springboot.mybatis: DEBUG
11 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/resources/data.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO MEMBER (ID, NAME, PHONE) VALUES (1, 'xml', '010-9912-1234');
2 | INSERT INTO MEMBER (ID, NAME, PHONE) VALUES (2, 'annotation', '010-2333-4321');
3 |
4 | INSERT INTO MEMBER_GROUP (ID, NAME, REMARK) VALUES (1, 'Team1', 'Test1 group');
5 | INSERT INTO MEMBER_GROUP (ID, NAME, REMARK) VALUES (2, 'Team2', 'Test2 group');
6 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE MEMBER (
2 | ID INT PRIMARY KEY,
3 | NAME VARCHAR(50),
4 | PHONE VARCHAR(20));
5 |
6 | CREATE TABLE MEMBER_GROUP (
7 | ID INT PRIMARY KEY,
8 | NAME VARCHAR(50),
9 | REMARK VARCHAR(20));
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-groovy/src/test/java/sample/springboot/mybatis/groovymapper/SpringDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.groovymapper;
2 |
3 | import static org.hamcrest.Matchers.*;
4 | import static org.junit.Assert.*;
5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
6 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
8 |
9 | import java.util.List;
10 |
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.boot.test.SpringApplicationConfiguration;
18 | import org.springframework.http.MediaType;
19 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20 | import org.springframework.test.context.web.WebAppConfiguration;
21 | import org.springframework.test.web.servlet.MockMvc;
22 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
23 | import org.springframework.web.context.WebApplicationContext;
24 |
25 | import sample.springboot.mybatis.groovymapper.SampleApplication;
26 | import sample.springboot.mybatis.groovymapper.SpringDemoApplicationTests;
27 | import sample.springboot.mybatis.groovymapper.service.Member;
28 | import sample.springboot.mybatis.groovymapper.service.MemberMapper;
29 | import sample.springboot.mybatis.groovymapper.web.MemberController;
30 |
31 | @RunWith(SpringJUnit4ClassRunner.class)
32 | @SpringApplicationConfiguration(classes = SampleApplication.class)
33 | @WebAppConfiguration
34 | public class SpringDemoApplicationTests {
35 | private static final Logger log = LoggerFactory.getLogger(SpringDemoApplicationTests.class);
36 |
37 | @Autowired
38 | WebApplicationContext wac;
39 |
40 | MockMvc mockMvc;
41 |
42 | @Before
43 | public void init() {
44 | mockMvc = MockMvcBuilders.webAppContextSetup(wac)
45 | .alwaysDo(print())
46 | .build();
47 | }
48 |
49 | @Test
50 | public void controllerMemberTest() throws Exception {
51 | mockMvc.perform(
52 | get("/member/{id}", 1).accept(MediaType.APPLICATION_JSON))
53 | .andExpect(handler().handlerType(MemberController.class))
54 | .andExpect(handler().methodName("member"))
55 | .andExpect(status().isOk())
56 | .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
57 | );
58 | }
59 |
60 | @Autowired
61 | MemberMapper memberMapper;
62 |
63 | @Test
64 | public void findAllTest() {
65 | List members = memberMapper.findAll();
66 | log.debug("members : {}", members);
67 | assertThat(members.size(), is(2));
68 | }
69 |
70 | @Test
71 | public void findByIdTest() {
72 | Member member1 = memberMapper.findById(1L);
73 | log.debug("member1 : {}", member1);
74 | assertThat(member1.getId(), is(1L));
75 | assertThat(member1.getName(), is("xml"));
76 | assertThat(member1.getPhone(), is("010-9912-1234"));
77 |
78 | Member member2 = memberMapper.findById(2L);
79 | log.debug("member2 : {}", member2);
80 | assertThat(member2.getId(), is(2L));
81 | assertThat(member2.getName(), is("annotation"));
82 | assertThat(member2.getPhone(), is("010-2333-4321"));
83 |
84 | Member member3 = memberMapper.findById(3L);
85 | log.debug("member3 : {}", member3);
86 | assertThat(member3, is(nullValue()));
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot.mybatis
7 | spring-boot-mybatis-sample
8 | 1.3.0.BUILD-SNAPSHOT
9 | ../
10 |
11 |
12 | spring-boot-mybatis-sample-hybrid
13 | jar
14 |
15 | spring-boot-mybatis-sample-hybrid
16 | Spring Boot MyBatis sample
17 |
18 |
19 | ${basedir}/../..
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.springframework.boot.mybatis
30 | spring-boot-mybatis
31 |
32 |
33 |
34 | com.h2database
35 | h2
36 | runtime
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-test
42 | test
43 |
44 |
45 |
46 |
47 |
48 |
49 | src/main/java
50 |
51 | **/*.java
52 | **/*.xml
53 |
54 |
55 |
56 | src/main/resources
57 |
58 |
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-maven-plugin
63 |
64 |
65 | org.apache.maven.plugins
66 | maven-surefire-plugin
67 |
68 | false
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/java/sample/springboot/mybatis/hybrid/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.hybrid;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SampleApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(SampleApplication.class, args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/java/sample/springboot/mybatis/hybrid/service/Member.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.hybrid.service;
2 |
3 | /**
4 | * Sample DTO
5 | *
6 | * @author sbcoba
7 | *
8 | */
9 | public class Member {
10 | private Long id;
11 | private String name;
12 | private String phone;
13 |
14 | public Long getId() {
15 | return id;
16 | }
17 | public void setId(Long id) {
18 | this.id = id;
19 | }
20 | public String getName() {
21 | return name;
22 | }
23 | public void setName(String name) {
24 | this.name = name;
25 | }
26 | public String getPhone() {
27 | return phone;
28 | }
29 | public void setPhone(String phone) {
30 | this.phone = phone;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "Member [id=" + id + ", name=" + name + ", phone=" + phone + "]";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/java/sample/springboot/mybatis/hybrid/service/MemberAnnotationMapper.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.hybrid.service;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Select;
6 | import org.springframework.boot.mybatis.autoconfigure.Mapper;
7 |
8 | @Mapper
9 | public interface MemberAnnotationMapper {
10 | @Select("SELECT id, name, phone FROM MEMBER where name = 'annotation'")
11 | List findAll();
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/java/sample/springboot/mybatis/hybrid/service/MemberXmlMapper.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.hybrid.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.boot.mybatis.autoconfigure.Mapper;
6 |
7 | /**
8 | * mapper.xml check
9 | * @author sbcoba
10 | *
11 | */
12 | @Mapper
13 | public interface MemberXmlMapper {
14 | List findAll();
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/java/sample/springboot/mybatis/hybrid/service/mapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/java/sample/springboot/mybatis/hybrid/web/MemberController.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.hybrid.web;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import sample.springboot.mybatis.hybrid.service.Member;
10 | import sample.springboot.mybatis.hybrid.service.MemberAnnotationMapper;
11 | import sample.springboot.mybatis.hybrid.service.MemberXmlMapper;
12 |
13 | @RestController
14 | public class MemberController {
15 |
16 | @Autowired
17 | MemberAnnotationMapper memberAnnotationMapper;
18 |
19 | @Autowired
20 | MemberXmlMapper memberXmlMapper;
21 |
22 | @RequestMapping(value="members")
23 | public List members() {
24 | return memberAnnotationMapper.findAll();
25 | }
26 |
27 | @RequestMapping(value="members", params="mapper=anno")
28 | public List annoMembers() {
29 | return memberAnnotationMapper.findAll();
30 | }
31 |
32 | @RequestMapping(value="members", params="mapper=xml")
33 | public List xmlMembers() {
34 | return memberXmlMapper.findAll();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | mybatis:
3 | # default value
4 | # annotationClass: org.springframework.boot.mybatis.autoconfigure.Mapper
5 | # configLocation: "mybatis-configuration.xml"
6 | mapper-locations: "classpath*:**/mapper.xml"
7 |
8 | # If the 'spring.mybatis.configLocation' property is used when the 'spring.mybatis.configurationProperties' property is ignored.
9 | configuration-properties:
10 | aggressiveLazyLoading: false
11 | lazyLoadingEnabled: true
12 | lazyLoadTriggerMethods: ""
13 | mapUnderscoreToCamelCase: true
14 |
15 | h2:
16 | console:
17 | path: /console
18 | enabled: true
19 |
20 | logging:
21 | level:
22 | org.springframework.boot: DEBUG
23 | org.hibernate: ERROR
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/resources/data.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO MEMBER (ID, NAME, PHONE) VALUES (1, 'xml', '010-9912-1234');
2 | INSERT INTO MEMBER (ID, NAME, PHONE) VALUES (2, 'annotation', '010-2333-4321');
3 |
4 | INSERT INTO MEMBER_GROUP (ID, NAME, REMARK) VALUES (1, 'Team1', 'Test1 group');
5 | INSERT INTO MEMBER_GROUP (ID, NAME, REMARK) VALUES (2, 'Team2', 'Test2 group');
6 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/resources/mybatis-configuration.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/main/resources/schema.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE MEMBER (
2 | ID INT PRIMARY KEY,
3 | NAME VARCHAR(50),
4 | PHONE VARCHAR(20));
5 |
6 | CREATE TABLE MEMBER_GROUP (
7 | ID INT PRIMARY KEY,
8 | NAME VARCHAR(50),
9 | REMARK VARCHAR(20));
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-hybrid/src/test/java/sample/springboot/mybatis/hybrid/SpringDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.hybrid;
2 |
3 | import static org.hamcrest.Matchers.*;
4 | import static org.junit.Assert.*;
5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
6 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
8 |
9 | import java.util.List;
10 | import java.util.Map;
11 |
12 | import org.junit.Before;
13 | import org.junit.Test;
14 | import org.junit.runner.RunWith;
15 | import org.slf4j.Logger;
16 | import org.slf4j.LoggerFactory;
17 | import org.springframework.beans.factory.annotation.Autowired;
18 | import org.springframework.boot.test.SpringApplicationConfiguration;
19 | import org.springframework.http.MediaType;
20 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
21 | import org.springframework.test.context.web.WebAppConfiguration;
22 | import org.springframework.test.web.servlet.MockMvc;
23 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
24 | import org.springframework.web.context.WebApplicationContext;
25 |
26 | import sample.springboot.mybatis.hybrid.service.Member;
27 | import sample.springboot.mybatis.hybrid.service.MemberAnnotationMapper;
28 | import sample.springboot.mybatis.hybrid.service.MemberXmlMapper;
29 | import sample.springboot.mybatis.hybrid.web.MemberController;
30 |
31 | @RunWith(SpringJUnit4ClassRunner.class)
32 | @SpringApplicationConfiguration(classes = SampleApplication.class)
33 | @WebAppConfiguration
34 | public class SpringDemoApplicationTests {
35 | private static final Logger log = LoggerFactory.getLogger(SpringDemoApplicationTests.class);
36 |
37 | @Autowired
38 | WebApplicationContext wac;
39 |
40 | MockMvc mockMvc;
41 |
42 | @Before
43 | public void init() {
44 | mockMvc = MockMvcBuilders.webAppContextSetup(wac)
45 | .alwaysDo(print())
46 | .build();
47 | }
48 |
49 | @Test
50 | public void controllerMembersAnnoTest() throws Exception {
51 | mockMvc.perform(
52 | get("/members").param("mapper", "anno").accept(MediaType.APPLICATION_JSON))
53 | .andExpect(handler().handlerType(MemberController.class))
54 | .andExpect(handler().methodName("annoMembers"))
55 | .andExpect(status().isOk())
56 | .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
57 | );
58 | }
59 |
60 | @Test
61 | public void controllerMemberXmlTest() throws Exception {
62 | mockMvc.perform(
63 | get("/members").param("mapper", "xml").accept(MediaType.APPLICATION_JSON))
64 | .andExpect(handler().handlerType(MemberController.class))
65 | .andExpect(handler().methodName("xmlMembers"))
66 | .andExpect(status().isOk())
67 | .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
68 | );
69 | }
70 |
71 | @Autowired
72 | MemberXmlMapper memberXmlMapper;
73 |
74 | @Test
75 | public void xmlFindAllTest() {
76 | List members = memberXmlMapper.findAll();
77 | log.debug("Members by xml mapper : {}", members);
78 | assertThat(members.size(), is(1));
79 | assertThat(members.get(0).getId(), is(1L));
80 | assertThat(members.get(0).getName(), is("xml"));
81 | assertThat(members.get(0).getPhone(), is("010-9912-1234"));
82 | }
83 |
84 | @Autowired
85 | MemberAnnotationMapper memberAnnotationMapper;
86 |
87 | @Test
88 | public void annotationFindAllTest() {
89 | List members = memberAnnotationMapper.findAll();
90 | log.debug("members by annotation mapper : {}", members);
91 | assertThat(members.size(), is(1));
92 | assertThat(members.get(0).getId(), is(2L));
93 | assertThat(members.get(0).getName(), is("annotation"));
94 | assertThat(members.get(0).getPhone(), is("010-2333-4321"));
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-simple/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /target/
3 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-simple/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot.mybatis
7 | spring-boot-mybatis-sample
8 | 1.3.0.BUILD-SNAPSHOT
9 | ../
10 |
11 |
12 | spring-boot-mybatis-sample-simple
13 | war
14 |
15 | spring-boot-mybatis-sample-simple
16 | Spring Boot MyBatis sample
17 |
18 |
19 | ${basedir}/../..
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-web
26 |
27 |
28 |
29 | org.springframework.boot.mybatis
30 | spring-boot-mybatis
31 |
32 |
33 |
34 | com.h2database
35 | h2
36 | runtime
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-test
42 | test
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-maven-plugin
51 |
52 |
53 | org.apache.maven.plugins
54 | maven-surefire-plugin
55 |
56 | false
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sample/spring-boot-mybatis-sample-simple/src/main/java/sample/springboot/mybatis/defaultconfig/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package sample.springboot.mybatis.defaultconfig;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import org.apache.ibatis.annotations.Select;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.SpringApplication;
9 | import org.springframework.boot.autoconfigure.SpringBootApplication;
10 | import org.springframework.boot.mybatis.autoconfigure.Mapper;
11 | import org.springframework.web.bind.annotation.PathVariable;
12 | import org.springframework.web.bind.annotation.RequestMapping;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | @SpringBootApplication
16 | public class SampleApplication {
17 |
18 | public static void main(String[] args) {
19 | SpringApplication.run(SampleApplication.class, args);
20 | }
21 |
22 | @RestController
23 | public static class MemberController {
24 |
25 | @Autowired
26 | MemberMapper memberMapper;
27 |
28 | @RequestMapping("members")
29 | public List