国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

MyBatis 系列:MyBatis 源碼環(huán)境搭建

這篇具有很好參考價(jià)值的文章主要介紹了MyBatis 系列:MyBatis 源碼環(huán)境搭建。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一、環(huán)境準(zhǔn)備

jdk:17

maven:3.9.5

二、下載 MyBatis 源碼和 MyBatis-Parent 源碼

Mybatis:https://github.com/mybatis/mybatis-3.git

Mybatis-Parent:https://github.com/mybatis/parent.git

建議使用git的方式拉取代碼,后期就不需要執(zhí)行git init

三、創(chuàng)建空項(xiàng)目、導(dǎo)入項(xiàng)目

導(dǎo)入兩個(gè)項(xiàng)目

MyBatis 系列:MyBatis 源碼環(huán)境搭建,mybatis,java

注意 mybatis-parent 必須采用 jdk版本:11-23,maven版本: 3.9.5

否則提示:

ERROR] Rule 1: org.apache.maven.enforcer.rules.version.RequireJavaVersion failed with message: [ERROR] Detected JDK version 1.8.0-361 (JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home/jre) is not in the allowed range [11,12),[17,18),[21,22),[22,23). [ERROR] Rule 2: org.apache.maven.enforcer.rules.version.RequireMavenVersion failed with message: [ERROR] Detected Maven Version: 3.6.3 is not in the allowed range [3.9.5,).

未來可能發(fā)生改變

設(shè)置為maven 3.9.5

MyBatis 系列:MyBatis 源碼環(huán)境搭建,mybatis,java

設(shè)置為java 17

MyBatis 系列:MyBatis 源碼環(huán)境搭建,mybatis,java

四、編譯 mybatis-parent

執(zhí)行命令

mvn clean install 

或者通過窗口執(zhí)行

MyBatis 系列:MyBatis 源碼環(huán)境搭建,mybatis,java

注意:如果出現(xiàn)Error: One of setGitDir or setWorkTree must be called.

執(zhí)行命令:git init

五、編譯 mybatis

修改成自己特有的版本,方便區(qū)分,避免與官網(wǎng)依賴相同版本

MyBatis 系列:MyBatis 源碼環(huán)境搭建,mybatis,java

執(zhí)行 maven 命令

mvn install -Dmaven.test.skip=true

PS:建議直接刪除test相關(guān)文件夾

注意:如果出現(xiàn):Could not get HEAD Ref, are you sure you have some commits in the dotGitDirectory (currently set to xxx/java-mybatis-source/mybatis-3-master/.git)?

執(zhí)行命令

git add .
git commit -m ‘xxx’

六、測(cè)試

  1. 添加mybati-test項(xiàng)目
  2. 引入依賴
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.5.16-DEMO</version>
    </dependency>
    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
      <version>8.3.0</version>
    </dependency>
  1. 添加數(shù)據(jù)庫(kù)
create database test;
create table if not exists test.user
(
    id         int auto_increment
        primary key,
    userName   varchar(50) not null,
    createTime datetime    not null
);
  1. 添加entity
package com.mcode.entity;

import java.time.LocalDateTime;

/**
 * ClassName: User
 * Package: com.mcode.entity
 * Description:
 *
 * @Author: robin
 * @Version: v1.0
 */
public class User {
    private int id;
    private String userName;

    private LocalDateTime createTime;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
}
  1. 添加 UserMapper
package com.mcode.mapper;

import com.mcode.entity.User;

/**
 * ClassName: UserMapper
 * Package: com.mcode.mapper
 * Description:
 *
 * @Author: robin
 * @Version: v1.0
 */
public interface UserMapper {
   User selectById(int id);
}
  1. 添加 mybatis-config.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>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost/test"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="./mappers/UserMapper.xml"/>
    </mappers>
</configuration>
  1. 添加 UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mcode.mapper.UserMapper">
    <!--namespace根據(jù)自己需要?jiǎng)?chuàng)建的的mapper的路徑和名稱填寫-->
    <select id="selectById" resultType="com.mcode.entity.User">
        select * from user where id = #{id}
    </select>
</mapper>
  1. 測(cè)試
package com.mcode;

import com.mcode.entity.User;
import com.mcode.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        String resource = "mybatis-config.xml";
        Reader reader;
        try {
            //將XML配置文件構(gòu)建為Configuration配置類
            reader = Resources.getResourceAsReader(resource);
            // 通過加載配置文件流構(gòu)建一個(gè)SqlSessionFactory  DefaultSqlSessionFactory
            SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
            // 數(shù)據(jù)源 執(zhí)行器  DefaultSqlSession
            SqlSession session = sqlMapper.openSession();
            try {
                UserMapper mapper = session.getMapper(UserMapper.class);
                System.out.println(mapper.getClass());
                User user = mapper.selectById(1);
                System.out.println(user.getUserName());
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                session.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

MyBatis 系列:MyBatis 源碼環(huán)境搭建,mybatis,java

問題:Cannot enable lazy loading because Javassist is not available. Add Javassist to your classpath.

看報(bào)錯(cuò)信息應(yīng)該是缺少Javassit的jar包,我們?nèi)?mybatis的源碼pom.xml把相應(yīng)的jar復(fù)制過來

     <dependency>
      <groupId>ognl</groupId>
      <artifactId>ognl</artifactId>
      <version>3.2.15</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.javassist</groupId>
      <artifactId>javassist</artifactId>
      <version>3.27.0-GA</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>

總結(jié)

不必過于糾結(jié)一些錯(cuò)誤,對(duì)于一些失敗的可以考慮直接注釋文章來源地址http://www.zghlxwxcb.cn/news/detail-822398.html

到了這里,關(guān)于MyBatis 系列:MyBatis 源碼環(huán)境搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【Java系列】Mybatis-Plus 使用介紹二

    【Java系列】Mybatis-Plus 使用介紹二

    你只管努力,其他交給時(shí)間,時(shí)間會(huì)證明一切。 MyBatis-Plus 是 MyBatis 的增強(qiáng)工具,它簡(jiǎn)化了 MyBatis 的開發(fā),并提供了許多實(shí)用的功能和工具類。下面是 MyBatis-Plus 的使用方法: 在 Maven 項(xiàng)目中,需要在 pom.xml 文件中添加如下依賴: 其中? mybatis-plus-boot-starter ?是 MyBatis-Plus 的 S

    2024年02月08日
    瀏覽(25)
  • 【Java系列】Mybatis-Plus 使用方式介紹

    【Java系列】Mybatis-Plus 使用方式介紹

    Mybatis-Plus 提供了多種方式來執(zhí)行 SQL,包括使用注解、XML 映射文件和 Lambda 表達(dá)式等。其中,使用 Lambda 表達(dá)式是 Mybatis-Plus 推薦的方式,因?yàn)樗又庇^和類型安全。 以下是一個(gè)使用 Lambda 表達(dá)式執(zhí)行 SQL 的示例,現(xiàn)在我們有一個(gè)名為? User ?的實(shí)體類,其中包含? id 、 name ?

    2024年02月07日
    瀏覽(27)
  • (一)前端環(huán)境搭建---基于SpringBoot+MySQL+Vue+ElementUI+Mybatis前后端分離面向小白管理系統(tǒng)搭建

    (一)前端環(huán)境搭建---基于SpringBoot+MySQL+Vue+ElementUI+Mybatis前后端分離面向小白管理系統(tǒng)搭建

    這里是為2023屆學(xué)生完成一個(gè)管理系統(tǒng)(主要是后臺(tái))的連續(xù)更新博客。持續(xù)時(shí)間為20天,每日練習(xí)時(shí)間約2-3小時(shí)。默認(rèn)已有系統(tǒng)開發(fā)的基礎(chǔ)知識(shí),如SpringBoot、數(shù)據(jù)庫(kù)、HTML、CSS、JavaScript等,連載過程中,遇到細(xì)節(jié)問題也可以咨詢。QQ群:1140508453。視頻將在B站推出。 B站鏈接:

    2023年04月23日
    瀏覽(27)
  • mybatis多參數(shù)傳遞報(bào)錯(cuò)問題分析+硬核mybatis底層源碼分析+@Param注解+圖文實(shí)戰(zhàn)環(huán)境分析【4500字詳解打通,沒有比這更詳細(xì)的了!】

    mybatis多參數(shù)傳遞報(bào)錯(cuò)問題分析+硬核mybatis底層源碼分析+@Param注解+圖文實(shí)戰(zhàn)環(huán)境分析【4500字詳解打通,沒有比這更詳細(xì)的了!】

    ?操作 mybatis 時(shí)報(bào)錯(cuò): org.apache.ibatis.binding.BindingException: Parameter ‘tableName’ not found. Available parameters are [arg1, arg0, param1, param2] Maven MySQL 8.0.30 在本機(jī) MySQL 中執(zhí)行: ?? pom.xml導(dǎo)入依賴 ?? jdbc.properties 在 resources 目錄下新建 jdbc.properties 配置文件。 ?? mybatis-config.xml 在 resources 目

    2024年02月12日
    瀏覽(20)
  • 【萬(wàn)字長(zhǎng)文】SpringBoot整合MyBatis搭建MySQL多數(shù)據(jù)源完整教程(提供Gitee源碼)

    前言:在我往期的博客介紹了2種關(guān)于如何使用SpringBoot搭建多數(shù)據(jù)源操作,本期博客我參考的是目前主流的框架,把最后一種整合多數(shù)據(jù)源的方式以博客的形式講解完,整合的過程比較傳統(tǒng)和復(fù)雜,不過我依舊會(huì)把每個(gè)實(shí)體類的思路都給大家講解清楚的,項(xiàng)目的最后我都會(huì)提

    2024年02月14日
    瀏覽(24)
  • Spring Boot學(xué)習(xí)隨筆- 集成MyBatis-Plus,第一個(gè)MP程序(環(huán)境搭建、@TableName、@TableId、@TableField示例)

    Spring Boot學(xué)習(xí)隨筆- 集成MyBatis-Plus,第一個(gè)MP程序(環(huán)境搭建、@TableName、@TableId、@TableField示例)

    學(xué)習(xí)視頻:【編程不良人】Mybatis-Plus整合SpringBoot實(shí)戰(zhàn)教程,提高的你開發(fā)效率,后端人員必備! MyBatis-Plus是一個(gè)基于MyBatis的增強(qiáng)工具,旨在簡(jiǎn)化開發(fā),提高效率。它擴(kuò)展了MyBatis的功能,提供了許多實(shí)用的特性,包括強(qiáng)大的CRUD操作、條件構(gòu)造器、分頁(yè)插件、代碼生成器等。MyBa

    2024年02月04日
    瀏覽(24)
  • Spring Boot學(xué)習(xí)隨筆- 集成MyBatis-Plus(一),第一個(gè)MP程序(環(huán)境搭建、@TableName、@TableId、@TableField示例)

    Spring Boot學(xué)習(xí)隨筆- 集成MyBatis-Plus(一),第一個(gè)MP程序(環(huán)境搭建、@TableName、@TableId、@TableField示例)

    學(xué)習(xí)視頻:【編程不良人】Mybatis-Plus整合SpringBoot實(shí)戰(zhàn)教程,提高的你開發(fā)效率,后端人員必備! MyBatis-Plus是一個(gè)基于MyBatis的增強(qiáng)工具,旨在簡(jiǎn)化開發(fā),提高效率。它擴(kuò)展了MyBatis的功能,提供了許多實(shí)用的特性,包括強(qiáng)大的CRUD操作、條件構(gòu)造器、分頁(yè)插件、代碼生成器等。MyBa

    2024年02月04日
    瀏覽(17)
  • Java版知識(shí)付費(fèi)源碼 Spring Cloud+Spring Boot+Mybatis+uniapp+前后端分離實(shí)現(xiàn)知識(shí)付費(fèi)平臺(tái)

    Java版知識(shí)付費(fèi)源碼 Spring Cloud+Spring Boot+Mybatis+uniapp+前后端分離實(shí)現(xiàn)知識(shí)付費(fèi)平臺(tái)

    知識(shí)付費(fèi)平臺(tái)主要指的是能夠通過付費(fèi)來滿足用戶知識(shí)需求的平臺(tái),用戶可以通過該平臺(tái)來消費(fèi)知識(shí)或者開展知識(shí)買賣等行為。 ? 此處的平臺(tái)是一個(gè)廣義的概念,可以是微信小程序或者論壇,也可以是網(wǎng)頁(yè)或者手機(jī)APP,等,就我國(guó)的情況而言,在知識(shí)付費(fèi)平臺(tái)發(fā)展初期,平臺(tái)

    2024年02月16日
    瀏覽(27)
  • java版工程管理系統(tǒng)Spring Cloud+Spring Boot+Mybatis實(shí)現(xiàn)工程管理系統(tǒng)源碼

    java版工程管理系統(tǒng)Spring Cloud+Spring Boot+Mybatis實(shí)現(xiàn)工程管理系統(tǒng)源碼

    ?工程項(xiàng)目管理軟件(工程項(xiàng)目管理系統(tǒng))對(duì)建設(shè)工程項(xiàng)目管理組織建設(shè)、項(xiàng)目策劃決策、規(guī)劃設(shè)計(jì)、施工建設(shè)到竣工交付、總結(jié)評(píng)估、運(yùn)維運(yùn)營(yíng),全過程、全方位的對(duì)項(xiàng)目進(jìn)行綜合管理 ???工程項(xiàng)目各模塊及其功能點(diǎn)清單 一、系統(tǒng)管理 ????1、數(shù)據(jù)字典:實(shí)現(xiàn)對(duì)數(shù)據(jù)字典

    2024年02月07日
    瀏覽(20)
  • 【Mybatis系列】Mybatis空值關(guān)聯(lián)

    【Mybatis系列】Mybatis空值關(guān)聯(lián)

    ??????歡迎來到我的博客,很高興能夠在這里和您見面!希望您在這里可以感受到一份輕松愉快的氛圍,不僅可以獲得有趣的內(nèi)容和知識(shí),也可以暢所欲言、分享您的想法和見解。 推薦:kwan 的首頁(yè),持續(xù)學(xué)習(xí),不斷總結(jié),共同進(jìn)步,活到老學(xué)到老 導(dǎo)航 檀越劍指大廠系列:全面總

    2024年01月17日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包