依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-devtools</artifactId>
  9. <scope>runtime</scope>
  10. <optional>true</optional>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.springframework.boot</groupId>
  14. <artifactId>spring-boot-starter-tomcat</artifactId>
  15. <scope>provided</scope>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework.boot</groupId>
  19. <artifactId>spring-boot-starter-test</artifactId>
  20. <scope>test</scope>
  21. </dependency> <dependency>
  22. <groupId>mysql</groupId>
  23. <artifactId>mysql-connector-java</artifactId>
  24. </dependency>
  25. <dependency>
  26. <groupId>org.springframework</groupId>
  27. <artifactId>spring-jdbc</artifactId>
  28. <version>4.3.15.RELEASE</version>
  29. </dependency>
  30. </dependencies>

代码

  1. @GetMapping("/hello")
  2. public String c_() {
  3. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  4. dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  5. dataSource.setUrl("jdbc:mysql://url地址:3306/数据库名字?useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai");
  6. dataSource.setUsername("cz_item");
  7. dataSource.setPassword("QAZwsx123");
  8. JdbcTemplate template = new JdbcTemplate(dataSource);
  9. List<Map<String, Object>> maps = template.queryForList("SELECT * FROM cz_item limit 10");
  10. return "你好";
  11. }

就是那么简单粗暴