Idea+Mybatis源码构建


准备工作:下载源码包

注意:

 Mybatis源码还依赖于一个父工程mybatis-parent,因此需要一起下载并且需要注意mybatis中引入的mybatis-parent的版本的版本得和自己下载的mybatis-parent的版本一致

mybatis-3-mybatis-3.5.5 源码下载
提取码:5t68
parent-mybatis-parent-31 源码下载
提取码:0z7b

如果想下载其他版本,可以去官方进行选择下载:
GitHub地址:https://github.com/mybatis/mybatis-3


一、将源码安装至本地仓库中

1.1 切换到你下载的mybatis-parent目录

 进入dos窗口

 执行命令:mvn clean install -Dmaven.test.skip=true看到BUILD SUCCESS  代表install成功

1.2 切换到你下载的mybatis源码目录(和1.1中的操作一致)

 执行命令:mvn clean install -Dmaven.test.skip=true

报错:

 pdf插件问题

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pdf-plugin:1.4:pdf (pdf) on project mybatis: Error during document generation: Error parsing C:\Users\sx\ws\mybatis_lg\ mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target\pdf\site.tmp\xdoc\getting-started.xml: Error parsing the model: only whitespace content allowed before sta rt tag and not \ufeff (position: COMMENT seen ...rning permissions and\n limitations under the License.\n\n-->\n\ufeff... @18:2) -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

解决:

 打开pom.xml 文件注释掉 maven-pdf-plugin 插件(可以选择把项目导入到idea中进行相关内容的删除,或者直接使用文本编辑工具进行删除)

重新install一次

 此时再次install,看到BUILD SUCCESS  代表install成功
C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5>mvn clean install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.mybatis:mybatis >-------------------------
[INFO] Building mybatis 3.5.5
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ mybatis ---
[INFO] Deleting C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M1:enforce (enforce-java) @ mybatis ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (prepare-agent) @ mybatis ---
[INFO] argLine set to -javaagent:C:\\Users\\sx\\sx_tools\\local_maven_repository\\org\\jacoco\\org.jacoco.agent\\0.8.5\\org.jacoco.agent-0.8.5-runtime.jar=destfile=C:\\Users\\sx\\ws
\\mybatis_lg\\mybatis_four_source\\mybatis-3-mybatis-3.5.5\\mybatis-3-mybatis-3.5.5\\target\\jacoco.exec,excludes=org.apache.ibatis.ognl.*:org.apache.ibatis.javassist.*
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ mybatis ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources to META-INF
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ mybatis ---
[INFO] Compiling 384 source files to C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target\classes
[INFO] /C:/Users/sx/ws/mybatis_lg/mybatis_four_source/mybatis-3-mybatis-3.5.5/mybatis-3-mybatis-3.5.5/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java: 某些输
入文件使用或覆盖了已过时的 API。
[INFO] /C:/Users/sx/ws/mybatis_lg/mybatis_four_source/mybatis-3-mybatis-3.5.5/mybatis-3-mybatis-3.5.5/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java: 有关详
细信息, 请使用 -Xlint:deprecation 重新编译。
[INFO] /C:/Users/sx/ws/mybatis_lg/mybatis_four_source/mybatis-3-mybatis-3.5.5/mybatis-3-mybatis-3.5.5/src/main/java/org/apache/ibatis/reflection/MetaObject.java: 某些输入文件使用了
未经检查或不安全的操作。
[INFO] /C:/Users/sx/ws/mybatis_lg/mybatis_four_source/mybatis-3-mybatis-3.5.5/mybatis-3-mybatis-3.5.5/src/main/java/org/apache/ibatis/reflection/MetaObject.java: 有关详细信息, 请使
用 -Xlint:unchecked 重新编译。
[INFO]
[INFO] --- license-maven-plugin:3.0:format (default) @ mybatis ---
[INFO] Updating license headers...
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.17:check (check-java-compat) @ mybatis ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO]
[INFO] --- maven-bundle-plugin:4.1.0:manifest (bundle-manifest) @ mybatis ---
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ mybatis ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ mybatis ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ mybatis ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.1:jar (default-jar) @ mybatis ---
[INFO] Building jar: C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target\mybatis-3.5.5.jar
[INFO]
[INFO] --- maven-shade-plugin:3.2.1:shade (default) @ mybatis ---
[INFO] Including ognl:ognl:jar:3.2.14 in the shaded jar.
[INFO] Including org.javassist:javassist:jar:3.27.0-GA in the shaded jar.
[INFO] Excluding org.slf4j:slf4j-api:jar:1.7.30 from the shaded jar.
[INFO] Excluding org.slf4j:slf4j-log4j12:jar:1.7.30 from the shaded jar.
[INFO] Excluding log4j:log4j:jar:1.2.17 from the shaded jar.
[INFO] Excluding org.apache.logging.log4j:log4j-core:jar:2.13.3 from the shaded jar.
[INFO] Excluding org.apache.logging.log4j:log4j-api:jar:2.13.3 from the shaded jar.
[INFO] Excluding commons-logging:commons-logging:jar:1.2 from the shaded jar.
[INFO] Excluding cglib:cglib:jar:3.3.0 from the shaded jar.
[INFO] Excluding org.ow2.asm:asm:jar:7.1 from the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target\mybatis-3.5.5.jar with C:\Users\sx\ws\mybatis_lg\mybatis_four_s
ource\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target\mybatis-3.5.5-shaded.jar
[INFO]
[INFO] --- maven-site-plugin:3.7.1:attach-descriptor (attach-descriptor) @ mybatis ---
[INFO] Skipping because packaging 'jar' is not pom.
[INFO]
[INFO] --- modernizer-maven-plugin:1.7.1:modernizer (modernizer) @ mybatis ---
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) @ mybatis ---
[INFO] Installing C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\target\mybatis-3.5.5.jar to C:\Users\sx\sx_tools\local_maven_reposito
ry\org\mybatis\mybatis\3.5.5\mybatis-3.5.5.jar
[INFO] Installing C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5\pom.xml to C:\Users\sx\sx_tools\local_maven_repository\org\mybatis\my
batis\3.5.5\mybatis-3.5.5.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.412 s
[INFO] Finished at: 2021-03-18T17:37:35+08:00
[INFO] ------------------------------------------------------------------------C:\Users\sx\ws\mybatis_lg\mybatis_four_source\mybatis-3-mybatis-3.5.5\mybatis-3-mybatis-3.5.5>

二、在idea中导入mybatis-parent和mybatis源码

三、在idea中创建测试项目

3.1 创建新的Module

 此时工程的目录结构如下

3.2 引入mybatis相应依赖,此处得引入我们上面构建的mybatis

 测试项目需要的其他的完整依赖
<dependencies><!--mybatis坐标--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.5</version></dependency><!--mysql驱动坐标--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.6</version><scope>runtime</scope></dependency><!--单元测试坐标--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><!--⽇志坐标--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.12</version></dependency></dependencies><build><!--修改pom文件中加上此resources即可解决--><resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource></resources></build>
3.3 新建Mapper接口和对应的映射文件

 AccountMapper.java
public interface AccountMapper {List<Account> findAll() throws IOException;Account findByCondition(Account account) throws IOException;List<Account> findByIds(int [] ids) throws IOException;Account findById(int id) throws IOException;
}
 AccountMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.dabing.source.mapper.AccountMapper"><select id="findAll" resultType="account">select * from Account</select><!--动态sql--><select id="findByCondition" parameterType="account" resultType="account">select * from Account<where><if test="id!=0">and id=#{id}</if><if test="username!=null">and username=#{username}</if></where></select><!--动态sql:循环执⾏sql的拼接操作--><select id="findByIds" parameterType="list" resultType="account">select * from Account<where><foreach collection="array" open="id in(" close=")" item="id"separator=",">#{id}</foreach></where></select><!--抽取sql⽚段简化编写--><sql id="selectAccount" >select * from Account</sql><select id="findById" parameterType="int" resultType="account"><include refid="selectAccount"></include> where id=#{id}</select></mapper>
3.4 新建mybatis配置文件,在resource目录下创建sqlMapConfig.xml文件:

 sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!--给实体类的全限定类名给别名--><typeAliases><!--批量起别名:该包下所有的类的本身的类名:别名还不区分大小写--><package name="com.dabing.source.pojo"/></typeAliases><!--environments:运行环境--><environments default="development"><environment id="development"><!--当前事务交由JDBC进行管理--><transactionManager type="JDBC"></transactionManager><!--当前使用mybatis提供的连接池--><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql:///zdy_mybatis"/><property name="username" value="root"/><property name="password" value="root"/></dataSource></environment></environments><!--引入映射配置文件--><mappers><package name="com.dabing.source.mapper"/></mappers></configuration>
3.5 编写测试类测试
 @Testpublic void test() throws IOException {InputStream resourceAsStream =Resources.getResourceAsStream("sqlMapConfig.xml");SqlSessionFactory sqlSessionFactory = newSqlSessionFactoryBuilder().build(resourceAsStream);SqlSession sqlSession = sqlSessionFactory.openSession();//获得MyBatis框架⽣成的UserMapper接⼝的实现类AccountMapper accountMapper = sqlSession.getMapper(AccountMapper.class);List<Account> accountMapperAll = accountMapper.findAll();for (Account account : accountMapperAll) {System.out.println(account);}sqlSession.close();}
 执行:报错

 解决:

 再次执行:执行成功

Idea+Mybatis源码构建相关推荐

  1. 从源码构建 MyBatis Generator(MBG)

    从源码构建 所有MyBatis Generator(MBG)发行版包括源代码,唯一的编译时间依赖关系在ant.jar上 - 用于成功编译包含的Ant任务.直接从源代码编译MBG - 只需将源解压缩到一 ...

  2. Mybatis源码本地化构建Demo

    目录 绪论 构建 SQL 配置文件 映射文件 Application 总结 绪论 上一篇文章中专门整理了如何构建Mybatis源码,小伙伴们可以在本地写demo跟踪或者注释修改源码等等骚操作...本篇 ...

  3. 如何优雅地本地化构建Mybatis源码

    目录 一.环境准备 二. 源码构建 2.1 parent 2.2mybatis源码 一.环境准备 不耽误各位想提升技术的热血沸腾的心情,不想啰嗦半天鸡汤废话,直接进入正题. 要想构建源码,大家都知道第 ...

  4. mybatis源码分析之事务管理器

    2019独角兽企业重金招聘Python工程师标准>>> 上一篇:mybatis源码分析之Configuration 主要分析了构建SqlSessionFactory的过程中配置文件的 ...

  5. Mybatis源码解读-设计模式总结

    虽然我们都知道有26个设计模式,但是大多停留在概念层面,真实开发中很少遇到,Mybatis源码中使用了大量的设计模式,阅读源码并观察设计模式在其中的应用,能够更深入的理解设计模式. Mybatis至少 ...

  6. MyBatis源码骨架分析

    源码包分析 MyBatis 源码下载地址:https://github.com/MyBatis/MyBatis-3 MyBatis源码导入过程: 下载MyBatis的源码 检查maven的版本,必须是 ...

  7. MyBatis源码-解读Executor的三个实现类之BatchExecutor(批处理执行器)

    文章目录 Pre Executor 执行器 接口继承关系 BatchExecutor(重用执行器) 入门小demo 源码 BatchExecutor VS ReuseExecutor Pre MyBa ...

  8. MyBatis源码-解读Executor的三个实现类之SimpleExecutor(简单执行器)

    文章目录 Pre Executor 执行器 接口继承关系 SimpleExecutor(简单执行器) 入门小demo 实例化SimpleExecutor doQuery方法 Pre MyBatis源码 ...

  9. MyBatis 源码分析 - 缓存原理

    1.简介 在 Web 应用中,缓存是必不可少的组件.通常我们都会用 Redis 或 memcached 等缓存中间件,拦截大量奔向数据库的请求,减轻数据库压力.作为一个重要的组件,MyBatis 自然 ...

  10. MyBatis 源码分析 - SQL 的执行过程

    本文速览 本篇文章较为详细的介绍了 MyBatis 执行 SQL 的过程.该过程本身比较复杂,牵涉到的技术点比较多.包括但不限于 Mapper 接口代理类的生成.接口方法的解析.SQL 语句的解析.运 ...

最新文章

  1. UI培训教程分享:常用的商业插画风格有哪些?
  2. Webpack 打包学习
  3. 安卓桌面软件哪个好_安卓模拟器哪个比较好?
  4. oracle odbc 设置_Oracle删除不干净怎么办?
  5. 高效的半同步/半异步模式的实现
  6. iframe多层嵌套时获取元素总结
  7. 我的docker随笔31:oracle数据库再次部署
  8. UI设计灵感|想让用户中心更有特色?这些案例值得借鉴
  9. php接收get数组数据,php-如何从wordpress数据库中获取数组值get_results
  10. HTML学习总结(1)——HTML基本介绍
  11. Steam帐号被盗怎么办
  12. WM_ERASEBKGND消息及位图背景与透明的实现
  13. win 11 大更新,新功能爱了爱了。
  14. Dubbo源码分析(一):概览
  15. 单片机秒表c语言程序设计思路,单片机秒表程序设计
  16. Webpack中 的css-loader和less-loader
  17. OS-实现一个RR调度算法
  18. 咏春拳段位首次开考先考动作再考功力2008-11-13
  19. 前端---------了解前端
  20. RK3399 Android7.1系统多个应用出现概率性打开闪退的问题

热门文章

  1. 网易云再度升级!用Python爬取下载(一:思路)
  2. 车机没有carlife可以自己下载吗_我可以忍受我的车上没有空调,但是我不能忍受我的车上没有CarPlay!...
  3. 关于极限编程简单介绍
  4. USB接线定义和链接摄像头
  5. Transcad学习记
  6. 离散数学第六版第er章偶数题答案_离散数学答案(尹宝林版)第二章习题解答
  7. Ubuntu20.04 安装matlab2017b
  8. CAD曲线快捷键是什么?CAD画曲线教程
  9. Matlab矩阵转置注意事项
  10. 520 miix 小兵 黑苹果,Hackintosh黑苹果长期维护机型整理清单