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

Mybatis—XML配置文件、動態(tài)SQL

這篇具有很好參考價值的文章主要介紹了Mybatis—XML配置文件、動態(tài)SQL。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

學(xué)習(xí)完Mybatis的基本操作之后,繼續(xù)學(xué)習(xí)Mybatis—XML配置文件、動態(tài)SQL。

Mybatis的XML配置文件

Mybatis的開發(fā)有兩種方式:

  1. 注解
  2. XML

之前學(xué)習(xí)的基本操作都是基于注解開發(fā)。使用Mybatis的注解方式,主要是來完成一些簡單的增刪改查功能。如果需要實現(xiàn)復(fù)雜的SQL功能,建議使用XML來配置映射語句,也就是將SQL語句寫在XML配置文件中。

XML配置文件規(guī)范

在Mybatis中使用XML映射文件方式開發(fā),需要符合一定的規(guī)范:

1. XML映射文件的名稱與Mapper接口名稱一致,并且將XML映射文件和Mapper接口放置在相同包下
(同包同名)
2. XML映射文件的namespace屬性為Mapper接口全限定名一致
3. XML映射文件中sql語句的id與Mapper接口中的方法名一致,并保持返回類型一致。

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

<select>標(biāo)簽:就是用于編寫select查詢語句的。
resultType屬性,指的是查詢返回的單條記錄所封裝的類型。

XML配置文件實現(xiàn)

第1步:創(chuàng)建XML映射文件

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

切記!: 在resource創(chuàng)建包時要用/分割符,如com/itheima/mapper,這樣才是在resource文件夾下創(chuàng)建了com文件夾,然后com文件夾里創(chuàng)建了itheima文件夾,如果創(chuàng)建包時復(fù)制路徑選錯,選擇復(fù)制了引用:com.itheima.mapper,那就只是在resource下創(chuàng)建了一個名字為“com.itheima.mapper”的子包,這樣系統(tǒng)就會報錯找不到XML映射文件!

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

第2步:編寫XML映射文件

xml映射文件中的dtd約束,直接從mybatis官網(wǎng)復(fù)制即可:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="">
 
</mapper>

配置:XML映射文件的namespace屬性為Mapper接口全限定名

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">

</mapper>

配置:XML映射文件中sql語句的id與Mapper接口中的方法名一致,并保持返回類型一致

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

最終xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">

    <!--查詢操作-->
    <select id="list" resultType="com.itheima.pojo.Emp">
        select * from emp
        where name like concat('%',#{name},'%')
              and gender = #{gender}
              and entrydate between #{begin} and #{end}
        order by update_time desc
    </select>
</mapper>

將Mapper接口中的select注解注釋掉,只保留接口方法,運(yùn)行測試類可發(fā)現(xiàn)與上一節(jié)中使用注解查詢的方法運(yùn)行結(jié)果相同。



MybatisX的使用

MybatisX是一款基于IDEA的快速開發(fā)Mybatis的插件,為效率而生。
MybatisX的安裝:

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

可以通過MybatisX快速定位:

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

MybatisX的使用在后續(xù)學(xué)習(xí)中會繼續(xù)分享





Mybatis動態(tài)SQL

SQL語句會隨著用戶的輸入或外部條件的變化而變化,我們稱為:動態(tài)SQL。

在頁面原型中,列表上方的條件是動態(tài)的,是可以不傳遞的,也可以只傳遞其中的1個或者2個或者全部:

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

而在我們剛才編寫的SQL語句中,我們會看到,我們將三個條件直接寫死了。 如果頁面只傳遞了參數(shù)姓名name 字段,其他兩個字段 性別 和 入職時間沒有傳遞,那么這兩個參數(shù)的值就是null:

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

正確的做法應(yīng)該是:傳遞了參數(shù),再組裝這個查詢條件;如果沒有傳遞參數(shù),就不應(yīng)該組裝這個查詢條件。

比如:如果姓名輸入了"張", 對應(yīng)的SQL為:

select *  from emp where name like '%張%' order by update_time desc;

如果姓名輸入了"張",,性別選擇了"男",則對應(yīng)的SQL為:

select *  from emp where name like '%張%' and gender = 1 order by update_time desc;

在Mybatis中提供了很多實現(xiàn)動態(tài)SQL的標(biāo)簽,我們學(xué)習(xí)Mybatis中的動態(tài)SQL就是掌握這些動態(tài)SQL標(biāo)簽。

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫



動態(tài)SQL-if

<if> :用于判斷條件是否成立。使用test屬性進(jìn)行條件判斷,如果條件為true,則拼接SQL。
<if test="條件表達(dá)式">
	要拼接的sql語句
</if>

條件查詢 <if>與<where>

  • 原有的SQL語句
<select id="list" resultType="com.itheima.pojo.Emp">
        select * from emp
        where name like concat('%',#{name},'%')
              and gender = #{gender}
              and entrydate between #{begin} and #{end}
        order by update_time desc
</select>
  • 動態(tài)SQL語句
<select id="list" resultType="com.itheima.pojo.Emp">
        select * from emp
        where
    
             <if test="name != null">
                 name like concat('%',#{name},'%')
             </if>
             <if test="gender != null">
                 and gender = #{gender}
             </if>
             <if test="begin != null and end != null">
                 and entrydate between #{begin} and #{end}
             </if>
    
        order by update_time desc
</select>

PS

如果判斷的類型是字符串類型最好加上空字符串判斷,如:
<if test="username != null and username != ''">
	username = #{username},
</if>

測試方法:

@Test
public void testList(){
    //性別數(shù)據(jù)為null、開始時間和結(jié)束時間也為null
    List<Emp> list = empMapper.list("張", null, null, null);
    for(Emp emp : list){
        System.out.println(emp);
    }
}

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

下面修改測試方法中的代碼,再次進(jìn)行測試,觀察執(zhí)行情況:

@Test
public void testList(){
    //姓名為null
    List<Emp> list = empMapper.list(null, (short)1, null, null);
    for(Emp emp : list){
        System.out.println(emp);
    }
}

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

再次修改測試方法中的代碼,再次進(jìn)行測試:

@Test
public void testList(){
    //傳遞的數(shù)據(jù)全部為null
    List<Emp> list = empMapper.list(null, null, null, null);
    for(Emp emp : list){
        System.out.println(emp);
    }
}

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫


以上問題的解決方案:使用<where> 標(biāo)簽代替SQL語句中的where關(guān)鍵字。

<where> 只會在子元素有內(nèi)容的情況下才插入where子句,而且會自動去除子句的開頭的AND或OR

<select id="list" resultType="com.itheima.pojo.Emp">
        select * from emp
        <where>
             <!-- if做為where標(biāo)簽的子元素 -->
             <if test="name != null">
                 and name like concat('%',#{name},'%')
             </if>
             <if test="gender != null">
                 and gender = #{gender}
             </if>
             <if test="begin != null and end != null">
                 and entrydate between #{begin} and #{end}
             </if>
        </where>
        order by update_time desc
</select>

測試方法:

@Test
public void testList(){
    //只有性別
    List<Emp> list = empMapper.list(null, (short)1, null, null);
    for(Emp emp : list){
        System.out.println(emp);
    }
}

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫



更新員工 <set>

動態(tài)更新員工信息,如果更新時傳遞有值,則更新;如果更新時沒有傳遞值,則不更新
解決方案:動態(tài)SQL

修改Mapper接口:

@Mapper
public interface EmpMapper {
    //刪除@Update注解編寫的SQL語句
    //update操作的SQL語句編寫在Mapper映射文件中
    public void update(Emp emp);
}

修改Mapper映射文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">

    <!--更新操作-->
    <update id="update">
        update emp
        set
            <if test="username != null">
                username=#{username},
            </if>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="gender != null">
                gender=#{gender},
            </if>
            <if test="image != null">
                image=#{image},
            </if>
            <if test="job != null">
                job=#{job},
            </if>
            <if test="entrydate != null">
                entrydate=#{entrydate},
            </if>
            <if test="deptId != null">
                dept_id=#{deptId},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime}
            </if>
        where id=#{id}
    </update>

</mapper>

測試方法:

@Test
public void testUpdate2(){
        //要修改的員工信息
        Emp emp = new Emp();
        emp.setId(20);
        emp.setUsername("Tom222");
      
        //調(diào)用方法,修改員工數(shù)據(jù)
        empMapper.update(emp);
}

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

以上問題的解決方案:使用<set> 標(biāo)簽代替SQL語句中的set關(guān)鍵字
<set> :動態(tài)的在SQL語句中插入set關(guān)鍵字,并會刪掉額外的逗號。(用于update語句中)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">

    <!--更新操作-->
    <update id="update">
        update emp
        <!-- 使用set標(biāo)簽,代替update語句中的set關(guān)鍵字 -->
        <set>
            <if test="username != null">
                username=#{username},
            </if>
            <if test="name != null">
                name=#{name},
            </if>
            <if test="gender != null">
                gender=#{gender},
            </if>
            <if test="image != null">
                image=#{image},
            </if>
            <if test="job != null">
                job=#{job},
            </if>
            <if test="entrydate != null">
                entrydate=#{entrydate},
            </if>
            <if test="deptId != null">
                dept_id=#{deptId},
            </if>
            <if test="updateTime != null">
                update_time=#{updateTime}
            </if>
        </set>
        where id=#{id}
    </update>
</mapper>

再次執(zhí)行測試方法,執(zhí)行的SQL語句:

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫



小結(jié)

  • <if>

    • 用于判斷條件是否成立,如果條件為true,則拼接SQL

    • 形式:

      <if test="name != null"></if>
      
  • <where>

    • where元素只會在子元素有內(nèi)容的情況下才插入where子句,而且會自動去除子句的開頭的AND或OR
  • <set>

    • 動態(tài)地在行首插入 SET 關(guān)鍵字,并會刪掉額外的逗號。(用在update語句中)



動態(tài)SQL-<foreach>

案例:員工刪除功能(既支持刪除單條記錄,又支持批量刪除)

SQL語句:

delete from emp where id in (1,2,3);

Mapper接口:

@Mapper
public interface EmpMapper {
    //批量刪除
    public void deleteByIds(List<Integer> ids);
}

XML映射文件:

  • 使用<foreach>遍歷deleteByIds方法中傳遞的參數(shù)ids集合
<foreach collection="集合名稱" item="集合遍歷出來的元素/項" separator="每一次遍歷使用的分隔符" 
         open="遍歷開始前拼接的片段" close="遍歷結(jié)束后拼接的片段">
</foreach>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">
    <!--刪除操作-->
    <delete id="deleteByIds">
        delete from emp where id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>
</mapper> 

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

測試類:

@SpringBootTest
class SpringbootMybatisCrudApplicationTests {
    @Autowired
    private EmpMapper empMapper;

    @Test
    public void testUpdate2(){
        //要修改的員工id
        List<Integer> ids = Arrays.asList(1,2,3);

        //調(diào)用方法,修改員工數(shù)據(jù)
        empMapper.deleteByIds(ids);
    }
}

執(zhí)行的SQL語句:

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫




動態(tài)SQL-<sql>&<include>

問題:在xml映射文件中配置的SQL,有時可能會存在很多重復(fù)的片段,此時就會存在很多冗余的代碼

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

我們可以對重復(fù)的代碼片段進(jìn)行抽取,將其通過<sql>標(biāo)簽封裝到一個SQL片段,然后再通過<include>標(biāo)簽進(jìn)行引用。

  • <sql>:定義可重用的SQL片段

  • <include>:通過屬性refid,指定包含的SQL片段

Mybatis—XML配置文件、動態(tài)SQL,數(shù)據(jù)庫,mybatis,xml,sql,mysql,數(shù)據(jù)庫

SQL片段: 抽取重復(fù)的代碼
然后通過<include> 標(biāo)簽在原來抽取的地方進(jìn)行引用。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">

    <sql id="commonSelect">
        select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp
    </sql>

    <select id="list" resultType="com.itheima.pojo.Emp">
        <include refid="commonSelect"/>
        <where>
            <if test="name != null">
                name like concat('%',#{name},'%')
            </if>
            <if test="gender != null">
                and gender = #{gender}
            </if>
            <if test="begin != null and end != null">
                and entrydate between #{begin} and #{end}
            </if>
        </where>
        order by update_time desc
    </select>
</mapper>



動態(tài)SQL中的特殊符號(大于,小于,不等于)使用注意事項

大于(>,>=)、小于(<,<=)、不等于(<> ,!=)符號包含了尖括號,Mybatis使用的 *.xml文件格式。于是需要進(jìn)行相關(guān)的轉(zhuǎn)義或者使用 CDATA 區(qū)段。嚴(yán)格地講,在 XML 中僅有字符 “<“和”&” 是非法的。省略號、引號和大于號是合法的,但是把它們都替換為實體引用是個好的習(xí)慣。

可以參考java特殊文件 屬性文件properties和XML文件,和Mybatis 特殊符號(大于,小于,不等于)及常用函數(shù)總結(jié)文章來源地址http://www.zghlxwxcb.cn/news/detail-736314.html

到了這里,關(guān)于Mybatis—XML配置文件、動態(tài)SQL的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 解決IntelliJ IDEA在Mybatis 編寫mapper.xml SQL語句時不自動提示SQL語句和數(shù)據(jù)庫表的問題

    解決IntelliJ IDEA在Mybatis 編寫mapper.xml SQL語句時不自動提示SQL語句和數(shù)據(jù)庫表的問題

    在Idea中鏈接數(shù)據(jù)庫后,發(fā)現(xiàn)在MySql 的console中有SQL語句提示和數(shù)據(jù)表的提示,但是在編寫mapper.xml中發(fā)現(xiàn)并沒有提示,很煩,覺得效率下降。 在百度搜索后,發(fā)現(xiàn)了解決方法,出現(xiàn)了SQL語句的提示. 解決辦法: 按下alt + enter,選擇Language injection settings 然后選擇SQL即可,但是這種

    2024年02月16日
    瀏覽(28)
  • 數(shù)據(jù)庫操作不再困難,MyBatis動態(tài)Sql標(biāo)簽解析

    數(shù)據(jù)庫操作不再困難,MyBatis動態(tài)Sql標(biāo)簽解析

    MyBatis緩存原理 Mybatis的CachingExecutor與二級緩存 Mybatis plugin 的使用及原理 MyBatis四大組件Executor、StatementHandler、ParameterHandler、ResultSetHandler 詳解 MyBatis+Springboot 啟動到SQL執(zhí)行全流程 使用MyBatis,或者M(jìn)yBatis-plus,有一項重要的開發(fā)技能就是寫動態(tài)sql,動態(tài)sql能幫我們省略很多復(fù)雜邏

    2024年02月12日
    瀏覽(34)
  • MyBatis動態(tài)SQL:打造靈活可變的數(shù)據(jù)庫操作

    MyBatis動態(tài)SQL:打造靈活可變的數(shù)據(jù)庫操作

    動態(tài)SQL就是根據(jù)不同的條件或需求動態(tài)地生成查詢語句,比如動態(tài)搜索條件、動態(tài)表或列名、動態(tài)排序等。 在我們填寫一些信息時,有些信息是必填字段,有的則是非必填的,這些信息的傳入就需要使?動態(tài)標(biāo)簽 if來判斷了 創(chuàng)建這樣想學(xué)生表就可以進(jìn)行測試了 下面是xml語句

    2024年02月12日
    瀏覽(22)
  • MyBatis案例 | 使用映射配置文件實現(xiàn)CRUD操作——動態(tài)SQL優(yōu)化條件查詢

    MyBatis案例 | 使用映射配置文件實現(xiàn)CRUD操作——動態(tài)SQL優(yōu)化條件查詢

    本專欄主要是記錄學(xué)習(xí)完JavaSE后學(xué)習(xí)JavaWeb部分的一些知識點(diǎn)總結(jié)以及遇到的一些問題等,如果剛開始學(xué)習(xí)Java的小伙伴可以點(diǎn)擊下方連接查看專欄 本專欄地址:??JavaWeb Java入門篇: ??Java基礎(chǔ)學(xué)習(xí)篇 Java進(jìn)階學(xué)習(xí)篇(持續(xù)更新中):??Java進(jìn)階學(xué)習(xí)篇 本系列文章會將講述有關(guān)

    2024年02月02日
    瀏覽(41)
  • Mybatis 動態(tài)SQL條件查詢(注釋和XML方式都有)

    Mybatis 動態(tài)SQL條件查詢(注釋和XML方式都有)

    需求 : 根據(jù)用戶的輸入情況進(jìn)行條件查詢 新建了一個 userInfo2Mapper 接口,然后寫下如下代碼,聲明 selectByCondition 這個方法 我們先用XML的方式實現(xiàn) 在resources 中創(chuàng)建 Userinfo2XMLMapper.xml 文件 ?將 Userinfo2XMLMapper.xml 文件中的 namespace 進(jìn)行修改,改為 userInfo2Mapper 接口中的第一行 package 的

    2024年01月22日
    瀏覽(27)
  • mybatis xml多表查詢,子查詢,連接查詢,動態(tài)sql

    mybatis xml多表查詢,子查詢,連接查詢,動態(tài)sql

    student_type 表 student 表 Student 類 一個學(xué)生只有一個年級 Type 類 一個年級有多個學(xué)生,所以用 list 下列代碼中: 1 resultMap 里面property對應(yīng)實體類屬性,column對應(yīng)數(shù)據(jù)庫字段名 2 主鍵用 id 標(biāo)簽 其他用result 3 關(guān)聯(lián)查詢(子查詢和連接查詢) 連接查詢查一次 4 一個年級多個學(xué)生,所以

    2024年01月21日
    瀏覽(18)
  • 【Spring Boot】使用XML配置文件實現(xiàn)數(shù)據(jù)庫操作(一)

    SQL映射文件就是我們通常說的mapper.xml配置文件,主要實現(xiàn)SQL語句的配置和映射,同時實現(xiàn)Java的POJO對象與數(shù)據(jù)庫中的表和字段進(jìn)行映射關(guān)聯(lián)的功能。 1.1 mapper.xml的結(jié)構(gòu) 下面就來詳細(xì)介紹mapper.xml文件的結(jié)構(gòu)。首先看一個完整的mapper.xml示例:

    2024年02月10日
    瀏覽(31)
  • 在IDEA中配置MySQL數(shù)據(jù)庫連接以及在使用mybatis時設(shè)置sql語句的代碼提示功能

    在IDEA中配置MySQL數(shù)據(jù)庫連接以及在使用mybatis時設(shè)置sql語句的代碼提示功能

    在IDEA中配置MySQL數(shù)據(jù)庫連接以及在使用mybatis 時設(shè)置 sql語句的代碼提示功能 一:在IDEA中配置MySQL數(shù)據(jù)庫連接 第一步:在IDEA右側(cè)區(qū)域有database選項,點(diǎn)擊進(jìn)去 第二步:database ?- data soucre - mysql? ?第三步:配置連接信息,連接數(shù)據(jù)庫 ? 第四步:顯示的數(shù)據(jù)庫以及表的信息 ?第

    2024年02月14日
    瀏覽(36)
  • Mybatis|mapper配置文件xml位置

    Mybatis|mapper配置文件xml位置

    在核心配置文件mybatis-config.xml中設(shè)置映射文件位置 application.yml文件中添加配置: mybatis案例中和springboot中都是一樣的,只要目錄名和包名相同 需要在pom.xml中添加如下內(nèi)容 越努力,越幸運(yùn)! codefishyyf與你一起努力!

    2024年02月06日
    瀏覽(25)
  • MyBatis-config.xml配置文件

    MyBatis-config.xml配置文件

    ????????mybatis的核心配置文件(mybatis-config.xml),比如配置jdbc連接信息,注冊mapper等等,我們需要對這個配置文件有詳細(xì)的了解。 官網(wǎng)地址有詳細(xì)介紹?mybatis – MyBatis 3 | 配置 ????????在通常的情況下,我們會將jdbc的配置信息,寫在一個外部文件,然后引入到mybatis-co

    2024年02月03日
    瀏覽(16)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包