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>

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

  • 相关阅读:
    Bootstrap UI层收藏介绍
    你为什么离开上家公司?三大经典面试问题剖析
    浅谈常用的Web安全技术手段
    C#中yield关键字理解
    中小型研发团队架构实践三要点(转自原携程架构师张辉清)
    你确实应该学习并使用的 10 个 C# 特性
    ASP.NET MVC 异步Excel数据选择导出
    表格中控制tr的display:block在火狐中显示错乱的解决方法
    切图笔记
    表单验证jquery.validate
  • 原文地址:https://www.cnblogs.com/wisdin/p/12603306.html
Copyright © 2011-2022 走看看