springboot关联mybaits

栏目: Java · 发布时间: 6年前

内容简介:注意: 该springboot版本oracle更新不下来, 需要从网上下载jar和pom 文件放到本地的maven库中;二.关联数据库, 编写代码, 增加相关配置1.需要在springboot项目启动类上面另外添加下面注解,用来扫描Mapper包下的类;
用springboot关联mybatis

一. 通过pom, 引入mybatis相关的jar

<dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.2.0</version>
        <!--<version>1.3.2</version>-->
    </dependency>

注意: 该springboot版本oracle更新不下来, 需要从网上下载jar和pom 文件放到本地的maven库中;

二.关联数据库, 编写代码, 增加相关配置

1.需要在springboot项目启动类上面另外添加下面注解,用来扫描Mapper包下的类;

@SpringBootApplication
@MapperScan("com.example.demo.***mapper")

2.配置连接数据库的相关

datasource:
    url: jdbc:oracle:thin:@****.dvpt:1521:****
    username: ***
    password: ***!
    driver-class-name: oracle.jdbc.OracleDriver
 mybatis:
   typeAliasesPackage: com.example.demo.entity
   mapperLocations: classpath:mapper/*.xml

3.编写mybatis相关

在Mapper的接口上添加 @Mapper 注解;

同时需要注意, sql文件的名字需要和map文件相同;

注意在 sql 文件中namespace 和 type 不要写成一样的;

springboot关联mybaits

  1. 编写服务类, 展现类以及thymeleaf页面

    这里没有什么说的 , 我记下我觉得需要注意的点

    ① service实现类需要 @Service 注解

    ② controller类中需要使用 @controller + @ResponseBody

三. springboot 热加载技术
这个网上说了好多 ,  我把我的配置展现下.

1.首先需要加入 devtools 插件的pom配置

<!-- 热部署模块 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional><!-- 这个需要为 true 热部署才有效 -->
    </dependency>

2.需要在yml中添加缓存, 热部署的路径 这两个配置;

springboot关联mybaits

这两个条件完成后, 还是没有起作用的话, 需要如下配置一

springboot关联mybaits

]

这样就算整合完成了;

展现一下我的项目目录, 方便观看

springboot关联mybaits


以上所述就是小编给大家介绍的《springboot关联mybaits》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

A Guide to Monte Carlo Simulations in Statistical Physics

A Guide to Monte Carlo Simulations in Statistical Physics

Landau, David P./ Binder, Kurt / Cambridge Univ Pr / 2005-9 / 786.00元

This new and updated edition deals with all aspects of Monte Carlo simulation of complex physical systems encountered in condensed-matter physics, statistical mechanics, and related fields. After brie......一起来看看 《A Guide to Monte Carlo Simulations in Statistical Physics》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试