实体类构建使用 generator
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>
<!--数据库驱动-->
<classPathEntry location="E:\work\localRepository\com\oracle\ojdbc7\12.1.0\ojdbc7-12.1.0.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接地址账号密码-->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@xxx.xxx.xxx.xxx1521:orcl" userId="xxxx" password="xxxxx">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成Model类存放位置-->
<javaModelGenerator targetPackage="com.xxx.mall.domain" targetProject="E:\work\AndroidStudioWork\mall\mall-common\src\main\java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="mapper" targetProject="E:\work\AndroidStudioWork\mall\mall-service\src\main\resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--生成Dao类存放位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.xxxx.mall.dao" targetProject="E:\work\AndroidStudioWork\mall\mall-service\src\main\java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--生成对应表及类名-->
<table tableName="MALL_USER_ADDRESS" domainObjectName="MallUserAddress" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
pom.xml中添加
<!-- oracle数据 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0</version>
</dependency>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
双击执行 (会生成 实体类 xml配置文件 与dao文件 )
application.properties 配置数据库
#数据库
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@xx.xxx.xxx.xxxx:1521:orcl
spring.datasource.username=xxx
spring.datasource.password=xxx
Mybatis 文件扫描位置
mybatis.type-aliases-package=com.xxxx.mall.domain
mybatis.mapper-locations=classpath:/mapper/*.xml
MallWebApplication 配置扫描的
@MapperScan(basePackages = {“com.xxxx.mall.dao”})
@SpringBootApplication
public class MallWebApplication {
public static void main(String[] args) {
SpringApplication.run(MallWebApplication.class, args);
使用查询数据
@Resource
private MallUserAddressMapper userAddressMapper;