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>

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

  • 相关阅读:
    2015网易校招Java开发工程师(技术架构)在线笔试题
    2015百度校招用户行为分析研发工程师笔试题
    2016届百度实习生前端笔试题上海卷a
    数据库 三范式最简单最易记的解释
    从几个sample来学习JAVA堆、方法区、JAVA栈和本地方法栈
    C++中虚函数和纯虚函数的总结
    MFC一些基本控件操作的总结
    单文档多视图一些基本操作
    MFC单文档静态分割视图
    iOS通讯录相关知识-浅析
  • 原文地址:https://www.cnblogs.com/wisdin/p/12603306.html
Copyright © 2011-2022 走看看