zoukankan      html  css  js  c++  java
  • Springboot Mybatis Sqlserver初配

    Controller、Entity、Service、Mapper编写和spring一致

    其他配置注意:

    1、启动类需添加两个注解:

      @SpringBootApplication
      @MapperScan("com.xx.xx.Mapper") //扫描Mapper接口

    2、Mapper接口类,需添加注解:@Mapper

    3、Mapper.xml配置:按spring方式配置即可

      ①位置放置要和下面的mybatis-locations保持一致哦,不然会读取不到(resources包内);

      ②如果不配置Mapper.xml,也可以使用注释方式设置语句,在mapper接口内对应的位置使用注释,如@Select("Select * from xxx")

    4、application.yml配置

    server: 
     port: xxxx   #当多个项目时,可重设端口号;可不重新设置,则为默认你本机端口号
     
    spring:
      datasource:
        url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=xxx
        driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
        username: xx
        password: xxxxx
           
    mybatis:
      mapper-locations: classpath:mybatis/mapper/*.xml
      type-aliases-package: com.xx.xx.Entity

    5、pom.xml配置:

    --首先记得加载sqlserver依赖配置

     <dependencies>

      <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <scope>runtime</scope>
            </dependency>

     </dependencies>

    --第二,静态资源包位置也要记得配置正确

    <resources>
          <resource>
              <!--   描述存放资源的目录,该路径相对POM路径-->
              <directory>src/main/java</directory>
              <includes>
                  <include>**/*.xml</include>
                  <include>**/*.yml</include>
              </includes>
              <filtering>false</filtering>
          </resource>
          <resource>
              <directory>src/main/resources</directory>
              <includes>
                  <include>**/*.xml</include>
                  <include>**/*.yml</include>
              </includes>
              <filtering>false</filtering>
          </resource>
      </resources>

    --第三,其他按需加载依赖

  • 相关阅读:
    tornado硬件管理系统-数据存储与表格实时监控(8)
    db2 内存研究
    Oracle dml开始到commit期间的流程
    用户界面与业务逻辑的分离
    计算器核心算法——终结版
    计算器核心算法——中缀表达式转为后缀表达式
    计算器核心解析算法(上)
    Qt中的字符串类
    初探Qt中的消息处理
    计算器界面代码重构
  • 原文地址:https://www.cnblogs.com/wisdin/p/12603306.html
Copyright © 2011-2022 走看看