├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
├── sql
└── myblog.sql
└── src
├── main
└── java
│ └── xyz
│ └── coolblog
│ ├── chapter1
│ ├── dao
│ │ └── ArticleDao.java
│ ├── dao2
│ │ ├── ArticleDao.java
│ │ └── AuthorDao.java
│ ├── model
│ │ └── Article.java
│ ├── model2
│ │ ├── Article.java
│ │ └── Author.java
│ └── model3
│ │ └── Article.java
│ ├── chapter3
│ └── model
│ │ └── Article.java
│ ├── chapter4
│ ├── dao
│ │ ├── ArticleDao.java
│ │ └── AuthorDao.java
│ ├── model
│ │ ├── Article.java
│ │ └── Author.java
│ └── model1
│ │ ├── Article.java
│ │ └── Author.java
│ ├── chapter6
│ ├── dao
│ │ └── StudentDao.java
│ └── model
│ │ └── Student.java
│ ├── chapter7
│ ├── dao
│ │ └── StudentDao.java
│ └── model
│ │ └── Student.java
│ ├── constant
│ ├── ArticleCategoryEnum.java
│ ├── ArticleTypeEnum.java
│ └── SexEnum.java
│ └── mybatis
│ ├── ArticleTypeHandler.java
│ ├── ExamplePlugin.java
│ ├── LoggableObjectFactory.java
│ └── MySqlPagingPlugin.java
└── test
├── java
└── xyz
│ └── coolblog
│ ├── chapter1
│ ├── HibernateTest.java
│ ├── JdbcTest.java
│ ├── MyBatisTest.java
│ ├── MyBatisTest2.java
│ ├── SpringJdbcTest.java
│ └── SpringWithMyBatisTest.java
│ ├── chapter2
│ └── MetaClassTest.java
│ ├── chapter3
│ └── ResultMapTest.java
│ ├── chapter4
│ ├── InsertManyTest.java
│ ├── OneToOneTest.java
│ ├── ParamNameResolverTest.java
│ ├── SqlNodeTest.java
│ └── SqlSourceBuilderTest.java
│ ├── chapter6
│ └── TransactionalCacheTest.java
│ └── chapter7
│ └── PluginTest.java
└── resources
├── chapter1
├── application-mybatis.xml
├── application.xml
├── hibernate.cfg.xml
├── mapper
│ └── ArticleMapper.xml
├── mapper2
│ ├── ArticleMapper.xml
│ └── AuthorMapper.xml
├── mapping
│ └── Article.hbm.xml
├── mybatis-config.xml
├── mybatis-config2.xml
└── mybatis-config3.xml
├── chapter3
└── mapper
│ └── ArticleMapper.xml
├── chapter4
├── mapper
│ ├── ArticleMapper.xml
│ └── AuthorMapper.xml
├── mybatis-config.xml
└── mybatis-config2.xml
├── chapter6
├── mapper
│ └── StudentMapper.xml
└── mybatis-config.xml
├── chapter7
├── mapper
│ └── StudentMapper.xml
└── mybatis-config.xml
├── jdbc.properties
└── log4j.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # IDEA
5 | .idea/
6 | *.iml
7 |
8 | target/
9 |
10 | # Log file
11 | *.log
12 |
13 | # BlueJ files
14 | *.ctxt
15 |
16 | # Mobile Tools for Java (J2ME)
17 | .mtj.tmp/
18 |
19 | # Package Files #
20 | *.jar
21 | *.war
22 | *.ear
23 | *.zip
24 | *.tar.gz
25 | *.rar
26 |
27 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28 | hs_err_pid*
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # mybatis-test
2 |
3 | ## 1.简介
4 |
5 | 《一本小小的MyBatis源码分析书》一书的附属源码,该书以电子书的形式发布,可免费下载。下载途径如下:
6 |
7 | 百度网盘:[点击下载](https://pan.baidu.com/s/1d0JTkab0gHOApXrMUbHGuQ)
8 |
9 |
10 |
11 |
12 |
13 | ## 2. 代码使用说明
14 |
15 | mybatis-test 项目的文件结构大致如下:
16 |
17 | ```
18 | .
19 | ├── sql
20 | │ └── myblog.sql
21 | ├── src
22 | ├── main
23 | │ ├── java
24 | │ └── resources
25 | └── test
26 | ├── java
27 | └── resources
28 | ```
29 |
30 | 使用步骤如下:
31 |
32 | 1. 执行 sql/myblog.sql 脚本,导入数据到数据库中
33 | 2. 修改 test/resources/log4j.properties 文件,将数据库配置改为你所使用的数据库
34 | 3. 执行 test/java/ 文件夹下的测试代码进行测试
35 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | 4.0.0
5 | xyz.coolblog
6 | mybatis-test
7 | war
8 | 1.0-SNAPSHOT
9 | mybatis-test Maven Webapp
10 | http://maven.apache.org
11 |
12 |
13 | 1.8
14 | 1.8
15 | 4.3.17.RELEASE
16 |
17 |
18 |
19 |
20 | org.mybatis
21 | mybatis
22 | 3.4.6
23 |
24 |
25 | org.mybatis
26 | mybatis-spring
27 | 1.3.2
28 |
29 |
30 |
31 | mysql
32 | mysql-connector-java
33 | 6.0.6
34 |
35 |
36 |
37 | org.springframework
38 | spring-core
39 | ${spring.version}
40 |
41 |
42 | org.springframework
43 | spring-beans
44 | ${spring.version}
45 |
46 |
47 | org.springframework
48 | spring-context
49 | ${spring.version}
50 |
51 |
52 | org.springframework
53 | spring-test
54 | ${spring.version}
55 | test
56 |
57 |
58 |
59 | org.springframework
60 | spring-jdbc
61 | ${spring.version}
62 |
63 |
64 |
65 | org.slf4j
66 | slf4j-api
67 | 1.7.25
68 |
69 |
70 | org.slf4j
71 | slf4j-log4j12
72 | 1.7.25
73 | test
74 |
75 |
76 | log4j
77 | log4j
78 | 1.2.17
79 |
80 |
81 |
82 | junit
83 | junit
84 | 4.12
85 | test
86 |
87 |
88 | org.hamcrest
89 | hamcrest-core
90 | 1.3
91 | test
92 |
93 |
94 | commons-lang
95 | commons-lang
96 | 2.6
97 |
98 |
99 |
100 | org.hibernate
101 | hibernate-core
102 | 5.3.2.Final
103 |
104 |
105 |
106 | com.google.code.gson
107 | gson
108 | 2.8.5
109 |
110 |
111 |
112 |
113 | mybatis-test
114 |
115 |
116 |
--------------------------------------------------------------------------------
/sql/myblog.sql:
--------------------------------------------------------------------------------
1 | # ************************************************************
2 | # Sequel Pro SQL dump
3 | # Version 4541
4 | #
5 | # http://www.sequelpro.com/
6 | # https://github.com/sequelpro/sequelpro
7 | #
8 | # Host: 127.0.0.1 (MySQL 5.7.20)
9 | # Database: myblog
10 | # Generation Time: 2018-09-09 11:05:33 +0000
11 | # ************************************************************
12 |
13 |
14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
17 | /*!40101 SET NAMES utf8 */;
18 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
19 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
20 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
21 |
22 |
23 | # Dump of table article
24 | # ------------------------------------------------------------
25 |
26 | DROP TABLE IF EXISTS `article`;
27 |
28 | CREATE TABLE `article` (
29 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
30 | `author_id` int(11) NOT NULL,
31 | `title` varchar(32) DEFAULT NULL,
32 | `type` tinyint(4) DEFAULT NULL,
33 | `content` text,
34 | `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
35 | PRIMARY KEY (`id`)
36 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
37 |
38 | LOCK TABLES `article` WRITE;
39 | /*!40000 ALTER TABLE `article` DISABLE KEYS */;
40 |
41 | INSERT INTO `article` (`id`, `author_id`, `title`, `type`, `content`, `create_time`)
42 | VALUES
43 | (1,1,'MyBatis 源码分析系列文章导读',8,'MyBatis 源码分析系列文章导读','2018-07-15 15:30:09'),
44 | (2,2,'HashMap 源码详细分析(JDK1.8)',1,'HashMap 源码详细分析(JDK1.8)','2018-01-18 15:29:13'),
45 | (3,1,'Java CAS 原理分析',1,'Java CAS 原理分析','2018-05-15 15:28:33'),
46 | (4,1,'Spring IOC 容器源码分析 - 获取单例 bean',4,'Spring IOC 容器源码分析 - 获取单例 bean','2018-06-01 00:00:00'),
47 | (5,1,'Spring IOC 容器源码分析 - 循环依赖的解决办法',4,'Spring IOC 容器源码分析 - 循环依赖的解决办法','2018-06-08 00:00:00'),
48 | (6,2,'Spring AOP 源码分析系列文章导读',4,'Spring AOP 源码分析系列文章导读','2018-06-17 00:00:00'),
49 | (7,2,'Spring AOP 源码分析 - 创建代理对象',4,'Spring AOP 源码分析 - 创建代理对象','2018-06-20 00:00:00'),
50 | (8,1,'Spring MVC 原理探秘 - 一个请求的旅行过程',4,'Spring MVC 原理探秘 - 一个请求的旅行过程','2018-06-29 00:00:00'),
51 | (9,2,'Spring MVC 原理探秘 - 容器的创建过程',4,'Spring MVC 原理探秘 - 容器的创建过程','2018-06-30 00:00:00'),
52 | (10,2,'Spring IOC 容器源码分析系列文章导读',4,'Spring IOC 容器源码分析系列文章导读','2018-05-30 00:00:00');
53 |
54 | /*!40000 ALTER TABLE `article` ENABLE KEYS */;
55 | UNLOCK TABLES;
56 |
57 |
58 | # Dump of table author
59 | # ------------------------------------------------------------
60 |
61 | DROP TABLE IF EXISTS `author`;
62 |
63 | CREATE TABLE `author` (
64 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
65 | `name` varchar(32) DEFAULT NULL,
66 | `age` tinyint(4) DEFAULT NULL,
67 | `sex` tinyint(4) DEFAULT NULL,
68 | `email` varchar(64) DEFAULT NULL,
69 | PRIMARY KEY (`id`)
70 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
71 |
72 | LOCK TABLES `author` WRITE;
73 | /*!40000 ALTER TABLE `author` DISABLE KEYS */;
74 |
75 | INSERT INTO `author` (`id`, `name`, `age`, `sex`, `email`)
76 | VALUES
77 | (1,'coolblog.xyz',28,0,'coolblog.xyz@outlook.com'),
78 | (2,'nullllun',29,1,'coolblog.xyz@outlook.com');
79 |
80 | /*!40000 ALTER TABLE `author` ENABLE KEYS */;
81 | UNLOCK TABLES;
82 |
83 |
84 | # Dump of table student
85 | # ------------------------------------------------------------
86 |
87 | DROP TABLE IF EXISTS `student`;
88 |
89 | CREATE TABLE `student` (
90 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
91 | `name` varchar(32) DEFAULT NULL,
92 | `age` tinyint(4) DEFAULT NULL,
93 | PRIMARY KEY (`id`)
94 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
95 |
96 | LOCK TABLES `student` WRITE;
97 | /*!40000 ALTER TABLE `student` DISABLE KEYS */;
98 |
99 | INSERT INTO `student` (`id`, `name`, `age`)
100 | VALUES
101 | (1,'coolblog',20);
102 |
103 | /*!40000 ALTER TABLE `student` ENABLE KEYS */;
104 | UNLOCK TABLES;
105 |
106 |
107 |
108 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
109 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
110 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
111 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
112 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
113 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
114 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/dao/ArticleDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.dao;
2 |
3 | import java.util.List;
4 | import org.apache.ibatis.annotations.Param;
5 | import xyz.coolblog.chapter1.model.Article;
6 |
7 | /**
8 | * ArticleDao
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-07-01 13:20:51
12 | */
13 | public interface ArticleDao {
14 | List findByAuthorAndCreateTime(@Param("author") String author, @Param("createTime") String createTime);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/dao2/ArticleDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.dao2;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import xyz.coolblog.chapter1.model2.Article;
5 |
6 | /**
7 | * ArticleDao
8 | *
9 | * @author Tian ZhongBo
10 | * @date 2018-07-01 13:20:51
11 | */
12 | public interface ArticleDao {
13 |
14 | Article findOne(@Param("id") int id);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/dao2/AuthorDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.dao2;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import xyz.coolblog.chapter1.model2.Author;
5 |
6 | /**
7 | * AuthorDao
8 | *
9 | * @author Tian ZhongBo
10 | * @date 2018-07-14 21:53:53
11 | */
12 | public interface AuthorDao {
13 |
14 | Author findOne(@Param("id") int id);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/model/Article.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | /**
8 | * Article
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-06-25 14:11:14
12 | */
13 | public class Article implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String title;
18 |
19 | private String author;
20 |
21 | private String content;
22 |
23 | private Date createTime;
24 |
25 | public Article() {
26 | }
27 |
28 | public Article(@Param("title") String title) {
29 | this.title = title;
30 | }
31 |
32 | public Article(@Param("id") Integer id, @Param("title") String title, @Param("content") String content) {
33 | this.id = id;
34 | this.title = title;
35 | this.content = content;
36 | }
37 |
38 | public Integer getId() {
39 | return id;
40 | }
41 |
42 | public void setId(Integer id) {
43 | this.id = id;
44 | }
45 |
46 | public String getTitle() {
47 | return title;
48 | }
49 |
50 | public void setTitle(String title) {
51 | this.title = title;
52 | }
53 |
54 | public String getAuthor() {
55 | return author;
56 | }
57 |
58 | public void setAuthor(String author) {
59 | this.author = author;
60 | }
61 |
62 | public String getContent() {
63 | return content;
64 | }
65 |
66 | public void setContent(String content) {
67 | this.content = content;
68 | }
69 |
70 | public Date getCreateTime() {
71 | return createTime;
72 | }
73 |
74 | public void setCreateTime(Date createTime) {
75 | this.createTime = createTime;
76 | }
77 |
78 | @Override
79 | public String toString() {
80 | return "Article{" +
81 | "id=" + id +
82 | ", title='" + title + '\'' +
83 | ", author='" + author + '\'' +
84 | ", content='" + content + '\'' +
85 | ", createTime=" + createTime +
86 | '}';
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/model2/Article.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.model2;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import xyz.coolblog.constant.ArticleTypeEnum;
6 |
7 | /**
8 | * Article
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-06-25 14:11:14
12 | */
13 | public class Article implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String title;
18 |
19 | private Author author;
20 |
21 | private String content;
22 |
23 | private ArticleTypeEnum type;
24 |
25 | private Date createTime;
26 |
27 | public Integer getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Integer id) {
32 | this.id = id;
33 | }
34 |
35 | public String getTitle() {
36 | return title;
37 | }
38 |
39 | public void setTitle(String title) {
40 | this.title = title;
41 | }
42 |
43 | public Author getAuthor() {
44 | return author;
45 | }
46 |
47 | public void setAuthor(Author author) {
48 | this.author = author;
49 | }
50 |
51 | public String getContent() {
52 | return content;
53 | }
54 |
55 | public void setContent(String content) {
56 | this.content = content;
57 | }
58 |
59 | public ArticleTypeEnum getType() {
60 | return type;
61 | }
62 |
63 | public void setType(ArticleTypeEnum type) {
64 | this.type = type;
65 | }
66 |
67 | public Date getCreateTime() {
68 | return createTime;
69 | }
70 |
71 | public void setCreateTime(Date createTime) {
72 | this.createTime = createTime;
73 | }
74 |
75 | @Override
76 | public String toString() {
77 | return "Article{" +
78 | "id=" + id +
79 | ", title='" + title + '\'' +
80 | ", author=" + author +
81 | ", content='" + content + '\'' +
82 | ", type=" + type +
83 | ", createTime=" + createTime +
84 | '}';
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/model2/Author.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.model2;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 | import xyz.coolblog.constant.SexEnum;
6 |
7 | /**
8 | * Author
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-07-14 21:54:45
12 | */
13 | public class Author implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String name;
18 |
19 | private Integer age;
20 |
21 | private SexEnum sex;
22 |
23 | private String email;
24 |
25 | private List articles;
26 |
27 | public Integer getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Integer id) {
32 | this.id = id;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public Integer getAge() {
44 | return age;
45 | }
46 |
47 | public void setAge(Integer age) {
48 | this.age = age;
49 | }
50 |
51 | public SexEnum getSex() {
52 | return sex;
53 | }
54 |
55 | public void setSex(SexEnum sex) {
56 | this.sex = sex;
57 | }
58 |
59 | public String getEmail() {
60 | return email;
61 | }
62 |
63 | public void setEmail(String email) {
64 | this.email = email;
65 | }
66 |
67 | public List getArticles() {
68 | return articles;
69 | }
70 |
71 | public void setArticles(List articles) {
72 | this.articles = articles;
73 | }
74 |
75 | @Override
76 | public String toString() {
77 | return "Author{" +
78 | "id=" + id +
79 | ", name='" + name + '\'' +
80 | ", age=" + age +
81 | ", sex=" + sex +
82 | ", email='" + email + '\'' +
83 | ", articles=" + articles +
84 | '}';
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter1/model3/Article.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter1.model3;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | /**
8 | * Article
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-06-25 14:11:14
12 | */
13 | public class Article implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String title;
18 |
19 | private String author;
20 |
21 | private String content;
22 |
23 | private Date createTime;
24 |
25 | public Article() {
26 | }
27 |
28 | public Article(@Param("title") String title) {
29 | this.title = title;
30 | }
31 |
32 | public Article(@Param("id") Integer id, @Param("title") String title, @Param("content") String content) {
33 | this.id = id;
34 | this.title = title;
35 | this.content = content;
36 | }
37 |
38 | public Integer getId() {
39 | return id;
40 | }
41 |
42 | public void setId(Integer id) {
43 | this.id = id;
44 | }
45 |
46 | public String getTitle() {
47 | return title;
48 | }
49 |
50 | public void setTitle(String title) {
51 | this.title = title;
52 | }
53 |
54 | public String getAuthor() {
55 | return author;
56 | }
57 |
58 | public void setAuthor(String author) {
59 | this.author = author;
60 | }
61 |
62 | public String getContent() {
63 | return content;
64 | }
65 |
66 | public void setContent(String content) {
67 | this.content = content;
68 | }
69 |
70 | public Date getCreateTime() {
71 | return createTime;
72 | }
73 |
74 | public void setCreateTime(Date createTime) {
75 | this.createTime = createTime;
76 | }
77 |
78 | @Override
79 | public String toString() {
80 | return "Article{" +
81 | "id=" + id +
82 | ", title='" + title + '\'' +
83 | ", author='" + author + '\'' +
84 | ", content='" + content + '\'' +
85 | ", createTime=" + createTime +
86 | '}';
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter3/model/Article.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter3.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | /**
8 | * Article
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-06-25 14:11:14
12 | */
13 | public class Article implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String title;
18 |
19 | private String author;
20 |
21 | private String content;
22 |
23 | private Date createTime;
24 |
25 | public Article() {
26 | }
27 |
28 | public Article(@Param("title") String title) {
29 | this.title = title;
30 | }
31 |
32 | public Article(@Param("id") Integer id, @Param("title") String title, @Param("content") String content) {
33 | this.id = id;
34 | this.title = title;
35 | this.content = content;
36 | }
37 |
38 | public Integer getId() {
39 | return id;
40 | }
41 |
42 | public void setId(Integer id) {
43 | this.id = id;
44 | }
45 |
46 | public String getTitle() {
47 | return title;
48 | }
49 |
50 | public void setTitle(String title) {
51 | this.title = title;
52 | }
53 |
54 | public String getAuthor() {
55 | return author;
56 | }
57 |
58 | public void setAuthor(String author) {
59 | this.author = author;
60 | }
61 |
62 | public String getContent() {
63 | return content;
64 | }
65 |
66 | public void setContent(String content) {
67 | this.content = content;
68 | }
69 |
70 | public Date getCreateTime() {
71 | return createTime;
72 | }
73 |
74 | public void setCreateTime(Date createTime) {
75 | this.createTime = createTime;
76 | }
77 |
78 | @Override
79 | public String toString() {
80 | return "Article{" +
81 | "id=" + id +
82 | ", title='" + title + '\'' +
83 | ", author='" + author + '\'' +
84 | ", content='" + content + '\'' +
85 | ", createTime=" + createTime +
86 | '}';
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter4/dao/ArticleDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter4.dao;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import xyz.coolblog.chapter4.model.Article;
5 | import xyz.coolblog.chapter4.model.Author;
6 |
7 |
8 | /**
9 | * ArticleDao
10 | *
11 | * @author Tian ZhongBo
12 | * @date 2018-07-01 13:20:51
13 | */
14 | public interface ArticleDao {
15 |
16 | Article findOne(@Param("id") int id);
17 |
18 | Author findAuthor(@Param("article_author_id") int authorId);
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter4/dao/AuthorDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter4.dao;
2 |
3 | import java.util.List;
4 | import xyz.coolblog.chapter4.model.Author;
5 |
6 | /**
7 | * StudentDao
8 | *
9 | * @author Tian ZhongBo
10 | * @date 2018-07-14 21:53:53
11 | */
12 | public interface AuthorDao {
13 |
14 | int insertMany(List authors);
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter4/model/Article.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter4.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import xyz.coolblog.constant.ArticleTypeEnum;
6 |
7 | /**
8 | * Article
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-06-25 14:11:14
12 | */
13 | public class Article implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String title;
18 |
19 | private ArticleTypeEnum type;
20 |
21 | private Author author;
22 |
23 | private String content;
24 |
25 | private Date createTime;
26 |
27 | public Article() {
28 | }
29 |
30 |
31 |
32 | public Article(Integer id, String title, String content) {
33 | this.id = id;
34 | this.title = title;
35 | this.content = content;
36 | }
37 |
38 | public Integer getId() {
39 | return id;
40 | }
41 |
42 | public void setId(Integer id) {
43 | this.id = id;
44 | }
45 |
46 | public String getTitle() {
47 | return title;
48 | }
49 |
50 | public void setTitle(String title) {
51 | this.title = title;
52 | }
53 |
54 | public ArticleTypeEnum getType() {
55 | return type;
56 | }
57 |
58 | public void setType(ArticleTypeEnum type) {
59 | this.type = type;
60 | }
61 |
62 | public Author getAuthor() {
63 | return author;
64 | }
65 |
66 | public void setAuthor(Author author) {
67 | this.author = author;
68 | }
69 |
70 | public String getContent() {
71 | return content;
72 | }
73 |
74 | public void setContent(String content) {
75 | this.content = content;
76 | }
77 |
78 | public Date getCreateTime() {
79 | return createTime;
80 | }
81 |
82 | public void setCreateTime(Date createTime) {
83 | this.createTime = createTime;
84 | }
85 |
86 | @Override
87 | public String toString() {
88 | return "Article{" +
89 | "id=" + id +
90 | ", title='" + title + '\'' +
91 | ", type=" + type +
92 | ", author=" + author +
93 | ", content='" + content + '\'' +
94 | ", createTime=" + createTime +
95 | '}';
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter4/model/Author.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter4.model;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Author
7 | *
8 | * @author Tian ZhongBo
9 | * @date 2018-07-14 21:54:45
10 | */
11 | public class Author implements Serializable {
12 |
13 | private Integer id;
14 |
15 | private String name;
16 |
17 | private Integer age;
18 |
19 | private Integer sex;
20 |
21 | private String email;
22 |
23 | public Author() {
24 | }
25 |
26 | public Author(String name, Integer age, Integer sex, String email) {
27 | this.name = name;
28 | this.age = age;
29 | this.sex = sex;
30 | this.email = email;
31 | }
32 |
33 | public Integer getId() {
34 | return id;
35 | }
36 |
37 | public void setId(Integer id) {
38 | this.id = id;
39 | }
40 |
41 | public String getName() {
42 | return name;
43 | }
44 |
45 | public void setName(String name) {
46 | this.name = name;
47 | }
48 |
49 | public Integer getAge() {
50 | return age;
51 | }
52 |
53 | public void setAge(Integer age) {
54 | this.age = age;
55 | }
56 |
57 | public Integer getSex() {
58 | return sex;
59 | }
60 |
61 | public void setSex(Integer sex) {
62 | this.sex = sex;
63 | }
64 |
65 | public String getEmail() {
66 | return email;
67 | }
68 |
69 | public void setEmail(String email) {
70 | this.email = email;
71 | }
72 |
73 | @Override
74 | public String toString() {
75 | return "Author{" +
76 | "id=" + id +
77 | ", name='" + name + '\'' +
78 | ", age=" + age +
79 | ", sex=" + sex +
80 | ", email='" + email + '\'' +
81 | '}';
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter4/model1/Article.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter4.model1;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | /**
8 | * Article
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-06-25 14:11:14
12 | */
13 | public class Article implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String title;
18 |
19 | private String author;
20 |
21 | private String content;
22 |
23 | private Date createTime;
24 |
25 | public Article() {
26 | }
27 |
28 | public Article(@Param("title") String title) {
29 | this.title = title;
30 | }
31 |
32 | public Article(@Param("id") Integer id, @Param("title") String title, @Param("content") String content) {
33 | this.id = id;
34 | this.title = title;
35 | this.content = content;
36 | }
37 |
38 | public Integer getId() {
39 | return id;
40 | }
41 |
42 | public void setId(Integer id) {
43 | this.id = id;
44 | }
45 |
46 | public String getTitle() {
47 | return title;
48 | }
49 |
50 | public void setTitle(String title) {
51 | this.title = title;
52 | }
53 |
54 | public String getAuthor() {
55 | return author;
56 | }
57 |
58 | public void setAuthor(String author) {
59 | this.author = author;
60 | }
61 |
62 | public String getContent() {
63 | return content;
64 | }
65 |
66 | public void setContent(String content) {
67 | this.content = content;
68 | }
69 |
70 | public Date getCreateTime() {
71 | return createTime;
72 | }
73 |
74 | public void setCreateTime(Date createTime) {
75 | this.createTime = createTime;
76 | }
77 |
78 | @Override
79 | public String toString() {
80 | return "Article{" +
81 | "id=" + id +
82 | ", title='" + title + '\'' +
83 | ", author='" + author + '\'' +
84 | ", content='" + content + '\'' +
85 | ", createTime=" + createTime +
86 | '}';
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter4/model1/Author.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter4.model1;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 | import xyz.coolblog.constant.SexEnum;
6 |
7 | /**
8 | * Author
9 | *
10 | * @author Tian ZhongBo
11 | * @date 2018-07-14 21:54:45
12 | */
13 | public class Author implements Serializable {
14 |
15 | private Integer id;
16 |
17 | private String name;
18 |
19 | private Integer age;
20 |
21 | private SexEnum sex;
22 |
23 | private String email;
24 |
25 | private List articles;
26 |
27 | public Integer getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Integer id) {
32 | this.id = id;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public Integer getAge() {
44 | return age;
45 | }
46 |
47 | public void setAge(Integer age) {
48 | this.age = age;
49 | }
50 |
51 | public SexEnum getSex() {
52 | return sex;
53 | }
54 |
55 | public void setSex(SexEnum sex) {
56 | this.sex = sex;
57 | }
58 |
59 | public String getEmail() {
60 | return email;
61 | }
62 |
63 | public void setEmail(String email) {
64 | this.email = email;
65 | }
66 |
67 | public List getArticles() {
68 | return articles;
69 | }
70 |
71 | public void setArticles(List articles) {
72 | this.articles = articles;
73 | }
74 |
75 | @Override
76 | public String toString() {
77 | return "Author{" +
78 | "id=" + id +
79 | ", name='" + name + '\'' +
80 | ", age=" + age +
81 | ", sex=" + sex +
82 | ", email='" + email + '\'' +
83 | ", articles=" + articles +
84 | '}';
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter6/dao/StudentDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter6.dao;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import xyz.coolblog.chapter6.model.Student;
5 |
6 | /**
7 | * StudentDao
8 | *
9 | * @author Tian ZhongBo
10 | * @date 2018-07-14 21:53:53
11 | */
12 | public interface StudentDao {
13 |
14 | Student findOne(@Param("id") Integer id);
15 |
16 | int update(@Param("id") Integer id, @Param("name") String name);
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter6/model/Student.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter6.model;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Student
7 | *
8 | * @author Tian ZhongBo
9 | * @date 2018-08-24 20:24:27
10 | */
11 | public class Student implements Serializable {
12 |
13 | private Integer id;
14 |
15 | private String name;
16 |
17 | private Integer age;
18 |
19 | public Integer getId() {
20 | return id;
21 | }
22 |
23 | public void setId(Integer id) {
24 | this.id = id;
25 | }
26 |
27 | public String getName() {
28 | return name;
29 | }
30 |
31 | public void setName(String name) {
32 | this.name = name;
33 | }
34 |
35 | public Integer getAge() {
36 | return age;
37 | }
38 |
39 | public void setAge(Integer age) {
40 | this.age = age;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Student{" +
46 | "id=" + id +
47 | ", name='" + name + '\'' +
48 | ", age=" + age +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter7/dao/StudentDao.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter7.dao;
2 |
3 | import java.util.List;
4 | import org.apache.ibatis.annotations.Param;
5 | import org.apache.ibatis.session.RowBounds;
6 | import xyz.coolblog.chapter7.model.Student;
7 |
8 | /**
9 | * StudentDao
10 | *
11 | * @author Tian ZhongBo
12 | * @date 2018-08-25 18:25:33
13 | */
14 | public interface StudentDao {
15 |
16 | List findByPaging(@Param("id") Integer id, RowBounds rb);
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/chapter7/model/Student.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.chapter7.model;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Student
7 | *
8 | * @author Tian ZhongBo
9 | * @date 2018-08-24 20:24:27
10 | */
11 | public class Student implements Serializable {
12 |
13 | private Integer id;
14 |
15 | private String name;
16 |
17 | private Integer age;
18 |
19 | public Integer getId() {
20 | return id;
21 | }
22 |
23 | public void setId(Integer id) {
24 | this.id = id;
25 | }
26 |
27 | public String getName() {
28 | return name;
29 | }
30 |
31 | public void setName(String name) {
32 | this.name = name;
33 | }
34 |
35 | public Integer getAge() {
36 | return age;
37 | }
38 |
39 | public void setAge(Integer age) {
40 | this.age = age;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return "Student{" +
46 | "id=" + id +
47 | ", name='" + name + '\'' +
48 | ", age=" + age +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/constant/ArticleCategoryEnum.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.constant;
2 |
3 | /**
4 | * ArticleCategoryEnum
5 | *
6 | * @author Tian ZhongBo
7 | * @date 2018-07-15 15:21:56
8 | */
9 | public enum ArticleCategoryEnum {
10 |
11 | JAVA(1),
12 | DUBBO(2),
13 | SPRING(3),
14 | MYBATIS(4);
15 |
16 | private int code;
17 |
18 | ArticleCategoryEnum(int code) {
19 | this.code = code;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/constant/ArticleTypeEnum.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.constant;
2 |
3 | /**
4 | * ArticleTypeEnum
5 | *
6 | * @author Tian ZhongBo
7 | * @date 2018-07-08 10:29:29
8 | */
9 | public enum ArticleTypeEnum {
10 |
11 | JAVA(1),
12 | DUBBO(2),
13 | SPRING(4),
14 | MYBATIS(8);
15 |
16 | private int code;
17 |
18 | ArticleTypeEnum(int code) {
19 | this.code = code;
20 | }
21 |
22 | public int code() {
23 | return code;
24 | }
25 |
26 | public static ArticleTypeEnum find(int code) {
27 | for (ArticleTypeEnum at : ArticleTypeEnum.values()) {
28 | if (at.code == code) {
29 | return at;
30 | }
31 | }
32 |
33 | return null;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/constant/SexEnum.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.constant;
2 |
3 | /**
4 | * SexEnum
5 | *
6 | * @author Tian ZhongBo
7 | * @date 2018-07-14 21:57:23
8 | */
9 | public enum SexEnum {
10 | MAN,
11 | FEMALE,
12 | UNKNOWN;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/mybatis/ArticleTypeHandler.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.mybatis;
2 |
3 | import java.sql.CallableStatement;
4 | import java.sql.PreparedStatement;
5 | import java.sql.ResultSet;
6 | import java.sql.SQLException;
7 | import org.apache.ibatis.type.BaseTypeHandler;
8 | import org.apache.ibatis.type.JdbcType;
9 | import org.apache.ibatis.type.MappedTypes;
10 | import xyz.coolblog.constant.ArticleTypeEnum;
11 | import xyz.coolblog.model.Article;
12 |
13 | /**
14 | * ArticleTypeHandler
15 | *
16 | * @author Tian ZhongBo
17 | * @date 2018-07-08 10:31:13
18 | */
19 | @MappedTypes(value = ArticleTypeEnum.class)
20 | public class ArticleTypeHandler extends BaseTypeHandler {
21 |
22 | @Override
23 | public void setNonNullParameter(PreparedStatement ps, int i, ArticleTypeEnum parameter, JdbcType jdbcType)
24 | throws SQLException {
25 | ps.setInt(i, parameter.code());
26 | }
27 |
28 | @Override
29 | public ArticleTypeEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
30 | int code = rs.getInt(columnName);
31 | return ArticleTypeEnum.find(code);
32 | }
33 |
34 | @Override
35 | public ArticleTypeEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
36 | int code = rs.getInt(columnIndex);
37 | return ArticleTypeEnum.find(code);
38 | }
39 |
40 | @Override
41 | public ArticleTypeEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
42 | int code = cs.getInt(columnIndex);
43 | return ArticleTypeEnum.find(code);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/mybatis/ExamplePlugin.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.mybatis;
2 |
3 | import java.lang.reflect.Method;
4 | import java.util.Properties;
5 | import org.apache.ibatis.executor.Executor;
6 | import org.apache.ibatis.mapping.MappedStatement;
7 | import org.apache.ibatis.plugin.Interceptor;
8 | import org.apache.ibatis.plugin.Intercepts;
9 | import org.apache.ibatis.plugin.Invocation;
10 | import org.apache.ibatis.plugin.Plugin;
11 | import org.apache.ibatis.plugin.Signature;
12 | import org.apache.ibatis.session.ResultHandler;
13 | import org.apache.ibatis.session.RowBounds;
14 |
15 | /**
16 | * ExamplePlugin
17 | *
18 | * @author Tian ZhongBo
19 | * @date 2018-07-06 11:31:50
20 | */
21 | @Intercepts({@Signature(
22 | type= Executor.class,
23 | method = "query",
24 | args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})})
25 | public class ExamplePlugin implements Interceptor {
26 |
27 | private Properties properties;
28 |
29 | @Override
30 | public Object intercept(Invocation invocation) throws Throwable {
31 | Method method = invocation.getMethod();
32 | Object[] args = invocation.getArgs();
33 | System.out.println(method + " - " + args);
34 | return invocation.proceed();
35 | }
36 |
37 | @Override
38 | public Object plugin(Object target) {
39 | return Plugin.wrap(target, this);
40 | }
41 |
42 | @Override
43 | public void setProperties(Properties properties) {
44 | this.properties = properties;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/xyz/coolblog/mybatis/LoggableObjectFactory.java:
--------------------------------------------------------------------------------
1 | package xyz.coolblog.mybatis;
2 |
3 | import java.util.List;
4 | import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | /**
9 | * LoggableObjectFactory
10 | *
11 | * @author Tian ZhongBo
12 | * @date 2018-07-06 10:22:26
13 | */
14 | public class LoggableObjectFactory extends DefaultObjectFactory {
15 |
16 | private Logger logger = LoggerFactory.getLogger(LoggableObjectFactory.class);
17 |
18 | @Override
19 | public T create(Class type) {
20 | // System.out.println("using default constructor create " + type);
21 | // logger.info("using default constructor create {}", type);
22 | return super.create(type);
23 | }
24 |
25 | @Override
26 | public T create(Class type, List> constructorArgTypes, List