Spring boot篇 myibatis 整合使用

实体类构建使用 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;

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值