Giter VIP home page Giter VIP logo

springcourse's Introduction

第一章 Hello World!

  1. 实现一个 SpringBoot 的接口后台,提供以下功能:

    • 访问 http://localhost:60038/hello 返回 Hello World!

    • 要点:

      • https://start.spring.io/ 生成基础代码,要加上 LombokSpring Web 依赖,不然用不了相关注解

      • 修改 src/main/resources/application.properties

        server.port=60038
        
      • 注解理解:@RestController,@RequestMapping("hello")

第二章 数据库

  1. 配置一个数据源,并连接获取一个表的信息,打印出来:

    • 通过自动加载的方式配置数据源

      • 在 stater.spring.io 选择依赖:H2, JDBC,Web,Actuator,Lombok
      • 不做特殊配置,直接运行,打印出连接相关信息。
      • 总结:
        1. CommandLineRunner 接口的使用
        2. @Autowried 类型:DataSource,JdbcTemplate
        3. 懒加载:dataSource.getConnection()
    • 不用 SpringBoot 的方式加载,需要自己写 dependency

      • 通过xml 的方式配置数据源

        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        	<property name="driverClassName" value="org.h2.Driver"/>
        	<property name="url" value="jdbc:h2:mem:testdb" />
        	<property name="username" value="SA" />
        	<property name="password" value="" />
        </bean>
        
      • 通过 @Bean 注释加载数据源

    • 通过 actuator/beans 查看 SQL 相关的 Bean

  2. 配置多数据源

    • 使用 @Primary 来配置
    • 不适用 @Primary 来配置,去掉自动加载类
  3. 使用阿里巴巴的 druid 数据库连接池,并添加一个自定义 Filter,在连接池连接之前和之后打印信息。

  4. 使用 JDBC 实现插入数据,批量插入数据,查询插入的数据。

    • 使用 SimpleJdbcInsert 实现插入
    • 使用 NamedParameterJdbcTemplate 实现插入
  5. 数据库中,不同数据库的 error code 是如何统一的,实现一个自定义的数据库错误。

    • 总结:
      • DuplicateKeyException 的使用
      • sql-error-codes.xml
      • JUnit5 与 JUnit4 的区别,Test 不带参数了,通过 Assertions.assertThrows 判断异常
  6. 使用编程式事务实现数据插入

    • 总结:
      • 获取数量,count(*),返回的是 long 类型
      • TransactionTemplate 的使用
  7. 使用声明式事务实现数据插入

    • 模仿抛出自定义异常

springcourse's People

Contributors

daz2yy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.