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示例暂时省略。

  • 相关阅读:
    8-4:Mysql数据库编程基础知识
    adb——Android的ADB工具使用
    BroadcastReceiver--Android广播机制
    怎样投篮更准
    《算法七》(深度寻路算法)
    《算法六》(有序二叉树)
    《算法五》(N叉树定义+增删改查)
    《算法四》(二分排序+汉诺塔问题)
    《算法三》(归并排序)
    《算法二》(希尔排序+基数排序+桶排序)
  • 原文地址:https://www.cnblogs.com/michaelShao/p/14517391.html
Copyright © 2011-2022 走看看