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

  • 相关阅读:
    django中的objects.get和objects.filter方法的区别
    Django之CSRF
    Django之include本质
    django中的FBV和CBV
    HTTP协议【详解】——经典面试题
    Python中的魔法函数__repr__和__str__的实质性区别
    浅谈CSS中的百分比
    深入理解定时器系列第一篇——理解setTimeout和setInterval
    Javascript学习
    HTML中块级元素和行内元素的总结和区分。
  • 原文地址:https://www.cnblogs.com/michaelShao/p/14517391.html
Copyright © 2011-2022 走看看