Record problem once mybatis genertor use and mapper scan met

  This record applies initial contact mybatis, Great God ignored. . .

 Overall two parts:

  1, code is automatically generated using mybatis genertor

  2, mapper scan

 

1, code is automatically generated using mybatis genertor

  First, add the pom in dependence

<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.6</version>
</dependency>

<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>


generatorConfig.xml configured as follows
<? xml Version = "1.0" encoding = "UTF-8"?> 
<DOCTYPE generatorConfiguration!
the PUBLIC "- // mybatis.org//DTD the Configuration MyBatis Generator 1.0 // EN"
"http://mybatis.org/dtd /mybatis-generator-config_1_0.dtd ">
<generatorConfiguration>
<- database driver:! select your local hard disk above database-driven package ->
<classpathentry LOCATION =" C: \ the Users \ Administrator \ .m2 \ Repository \ MySQL \ MySQL-Connector-Java \ 5.1.46 \ MySQL-Connector-Java-5.1.46.jar "/>
<context ID =" DB2Tables "targetRuntime =" MyBatis 3 ">
<commentGenerator>
<Property name =" suppressDate "value = "true" />
! <- true if the automatically generated annotation removal: is: to false: NO ->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/lilacfover?serverTimezone=UTC" userId="root" password="Crte@123">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.lilacfover.mybatisgenertor.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="to true "/> <-! package name and location of the mapping file generation targetProject may also be configured to src / main / java ->
</ javaModelGenerator>
        <sqlMapGenerator targetPackage = "Mapper" targetProject = "the src / main / Resources"> 
<Property name = "enableSubPackages" = value "to true" />
</ sqlMapGenerator>
<-! DAO generated name and location of the package ->
<javaClientGenerator = type "XMLMAPPER" targetPackage = "com.lilacfover.mybatisgenertor.dao" targetProject = "the src / main / Java">
<Property name = "enableSubPackages" = value "to true" />
</ javaClientGenerator>
<-! be generated tableName table is a database table or view name domainObjectName entity class name ->
<table tableName = "admin_user" domainObjectName = "the Admin" enableCountByExample = "to false"enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</ generatorConfiguration>

this configuration automatically generate clicks

 

 FIG finally generated as follows:

 

 

Then you can use directly, I'm here controler simply call for a moment:

 

 

2, mapper scan.

  If the data source is not configured maven application.properties only then scanned in resources configured xml: mybatis.mapper-locations = classpath:. Mapper / * xml

  But we will mapper java in this manner can not scan the need to configure the data source in the maven follows:

<resources>

<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>

然后在配置中配置xml扫描路径为:mybatis.mapper-locations= classpath:com/lilacfover/mybatisgenertor/mapper/*.xml

另外还要在mapper中添加@mapper注解

本次说明的地方大部分是我在使用中遇见的一些问题,希望对初次使用的有所帮助

Guess you like

Origin www.cnblogs.com/tpcwlilacfover/p/12189958.html