zoukankan      html  css  js  c++  java
  • SpringBoot学习2之注解简单配置Springboot+MyBatis

    1.创建springboot工程,pom文件主要包如下:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

    2.利用application.proprities创建数据源配置:

    # dataSource configuration
    spring.server.port = 8080
    spring.datasource.url=jdbc:postgresql://10.143.1.30:5491/temp
    spring.datasource.username=temp
    spring.datasource.password=temp
    spring.datasource.driverClassName=org.postgresql.Driver

    #mybatis configuration:讲数据库字段是下划线,改变为程序中使用驼峰
    mybatis.configuration.map-underscore-to-camel-case=true

    3.在SpringBootApplication类文件添加自动扫描注解:

      @MapperScan //作用:是将指定包下的接口自动生成实现类。

      通常配置SpringBootApplication类中

      @SpringBootApplication
      @MapperScan("com.sso.mapper")
      public class SsoApplication {

      public static void main(String[] args) {
          SpringApplication.run(SsoApplication.class, args);
        }

      }

           @Mapper //作用:是将指定的接口自动生成实现类。相当于是一个mapper.xml 文件

    4.创建mapper接口主要内容:

    public interface UserMapper {
    @Select("select * from user where user_id = #{id}")
      public Security getDays (String id);
    }

      

    5.其他controller,model示例暂时省略。

  • 相关阅读:
    《人月神话》阅读笔记(三)
    记账软件开发进度(六)
    记账软件开发进度(五)
    记账软件开发进度(四)
    《人月神话》阅读笔记(二)
    记账软件开发进度(三)
    package bufio
    Go语言:net/http包的使用模式和源码解析
    package http
    Golang系列中常用包
  • 原文地址:https://www.cnblogs.com/michaelShao/p/14517391.html
Copyright © 2011-2022 走看看