免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

Mybatis中Mapper文件的作用是什么-創(chuàng)新互聯(lián)

本篇文章為大家展示了Mybatis中Mapper文件的作用是什么,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

成都創(chuàng)新互聯(lián)是專業(yè)的相城網(wǎng)站建設(shè)公司,相城接單;提供網(wǎng)站設(shè)計制作、成都網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行相城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!

1|1插件依賴

<build>  <plugins>   <plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-maven-plugin</artifactId>   </plugin>   <plugin>    <groupId>org.mybatis.generator</groupId>    <artifactId>mybatis-generator-maven-plugin</artifactId>    <version>1.3.5</version>    <dependencies>     <dependency>      <groupId>mysql</groupId>      <artifactId>mysql-connector-java</artifactId>      <version>6.0.6</version>     </dependency>     <dependency>      <groupId>org.mybatis.generator</groupId>      <artifactId>mybatis-generator-core</artifactId>      <version>1.3.5</version>     </dependency>    </dependencies>    <!--<executions>-->     <!--<execution>-->      <!--<id>Generate MyBatis Artifacts</id>-->      <!--<phase>package</phase>-->      <!--<goals>-->       <!--<goal>generate</goal>-->      <!--</goals>-->     <!--</execution>-->    <!--</executions>-->    <configuration>     <!--允許移動生成的文件 -->     <verbose>true</verbose>     <!-- 是否覆蓋 -->     <overwrite>true</overwrite>     <!-- 自動生成的配置 -->     <configurationFile>      src/main/resources/generatorConfig.xml     </configurationFile>    </configuration>   </plugin>  </plugins> </build>

注意:mysql-connector-java的版本問題,如果你的驅(qū)動是com.mysql.cj.jdbc.Driver,你就需要6.0.x的版本。如果是com.mysql.jdbc.Driver 則是5.1.x的版本。

1|2配置generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration> <!--導(dǎo)入屬性配置--> <properties resource="datasource.properties"></properties> <!-- context 是逆向工程的主要配置信息 --> <!-- id:name --> <!-- targetRuntime:設(shè)置生成的文件適用于那個 mybatis 版本 --> <context id="default" targetRuntime="MyBatis3">  <!-- 生成的 Java 文件的編碼 -->  <property name="javaFileEncoding" value="UTF-8"/>  <!-- optional,旨在創(chuàng)建class時,對注釋進(jìn)行控制 -->  <commentGenerator>   <property name="suppressDate" value="true"/>   <property name="suppressAllComments" value="true"/>  </commentGenerator>  <!--jdbc的數(shù)據(jù)庫連接 -->  <jdbcConnection    driverClass="${db.driverClassName}"    connectionURL="${db.url}"    userId="${db.username}"    password="${db.password}">  </jdbcConnection>  <!-- 非必需,類型處理器,在數(shù)據(jù)庫類型和java類型之間的轉(zhuǎn)換控制-->  <javaTypeResolver>   <property name="forceBigDecimals" value="false"/>  </javaTypeResolver>  <!-- Model模型生成器,用來生成含有主鍵key的類,記錄類 以及查詢Example類   targetPackage  指定生成的model生成所在的包名   targetProject  指定在該項目下所在的路徑  -->  <!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".\src\main\java">-->  <javaModelGenerator targetPackage="com.ke.likehouse.model" targetProject="./src/main/java">   <!-- 是否允許子包,即targetPackage.schemaName.tableName -->   <property name="enableSubPackages" value="false"/>   <!-- 是否對model添加 構(gòu)造函數(shù) -->   <property name="constructorBased" value="true"/>   <!-- 是否對類CHAR類型的列的數(shù)據(jù)進(jìn)行trim操作 -->   <property name="trimStrings" value="true"/>   <!-- 建立的Model對象是否 不可改變 即生成的Model對象不會有 setter方法,只有構(gòu)造方法 -->   <property name="immutable" value="false"/>  </javaModelGenerator>  <!--mapper映射文件生成所在的目錄 為每一個數(shù)據(jù)庫的表生成對應(yīng)的SqlMap文件 -->  <!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->  <sqlMapGenerator targetPackage="mybatis/mappers" targetProject="./src/main/resources">   <property name="enableSubPackages" value="false"/>  </sqlMapGenerator>  <!-- 客戶端代碼,生成易于使用的針對Model對象和XML配置文件 的代碼    type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper對象    type="MIXEDMAPPER",生成基于注解的Java Model 和相應(yīng)的Mapper對象    type="XMLMAPPER",生成SQLMap XML文件和獨(dú)立的Mapper接口  -->  <!-- targetPackage:mapper接口dao生成的位置 -->  <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->  <javaClientGenerator type="XMLMAPPER" targetPackage="com.ke.likehouse.dao" targetProject="./src/main/java">   <!-- enableSubPackages:是否讓schema作為包的后綴 -->   <property name="enableSubPackages" value="false" />  </javaClientGenerator>  <!--生成的表-->  <!--domainObjectName:生成的domain類的名字,如果不設(shè)置,直接使用表名作為domain類的名字;可以設(shè)置為somepck.domainName,那么會自動把domainName類再放到somepck包里面;-->  <!--enableInsert(默認(rèn)true):指定是否生成insert語句;-->  <!--enableSelectByPrimaryKey(默認(rèn)true):指定是否生成按照主鍵查詢對象的語句(就是getById或get);-->  <!--enableSelectByExample(默認(rèn)true):MyBatis3Simple為false,指定是否生成動態(tài)查詢語句;-->  <!--enableUpdateByPrimaryKey(默認(rèn)true):指定是否生成按照主鍵修改對象的語句(即update);-->  <!--enableDeleteByPrimaryKey(默認(rèn)true):指定是否生成按照主鍵刪除對象的語句(即delete);-->  <!--enableDeleteByExample(默認(rèn)true):MyBatis3Simple為false,指定是否生成動態(tài)刪除語句;-->  <!--enableCountByExample(默認(rèn)true):MyBatis3Simple為false,指定是否生成動態(tài)查詢總條數(shù)語句(用于分頁的總條數(shù)查詢);-->  <!--enableUpdateByExample(默認(rèn)true):MyBatis3Simple為false,指定是否生成動態(tài)修改語句(只修改對象中不為空的屬性);-->  <table tableName="agent" domainObjectName="Agent"    enableCountByExample="false"    enableUpdateByExample="false"    enableDeleteByExample="false"    enableSelectByExample="false"    selectByExampleQueryId="false">  </table>  <!-- geelynote mybatis插件的搭建 --> </context></generatorConfiguration>

1|3提供datasource.properties

db.driverClassName = com.mysql.cj.jdbc.Driverdb.url = jdbc:mysql://localhost:3306/twelve?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=truedb.username = rootdb.password = 你的密碼

1|4執(zhí)行maven命令

方式一:通過IDEA的MAVEN工具執(zhí)行

方式二:通過MAVEN命令

配置命令:mybatis-generator:generate -e

然后Run就好了:

1|5可能出現(xiàn)的BUG

如果你復(fù)制粘貼了代碼卻出現(xiàn)稀奇古怪的BUG,很有可能是:

你的maven的配置文件問題  引用的mysql-connector-java與driverClassName版本不匹配  如果你的驅(qū)動是com.mysql.cj.jdbc.Driver,你就需要6.x.x的版本。如果是com.mysql.jdbc.Driver 則是5.x.x的版本。

上述內(nèi)容就是Mybatis中Mapper文件的作用是什么,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

新聞標(biāo)題:Mybatis中Mapper文件的作用是什么-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://newbst.com/article40/hhjho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)網(wǎng)站策劃外貿(mào)網(wǎng)站建設(shè)移動網(wǎng)站建設(shè)云服務(wù)器App設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)