Springboot from getting started to getting started (3 JDBC & MySQL)

wwz_ henu 2022-02-13 05:26:12 阅读数:838

springboot getting started getting started

One . add to dependency

stay pom.xml Add the following


Two . To configure dataSource

stay First article It is mentioned in that you can application.properties To configure , This approach is slightly complicated , Use application.yml To configure

port: 80
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://
username: root
password: root # Database name 、 Change the user name and password to your own 

3、 ... and . Create route

* Database tables are created in advance

private JdbcTemplate jdbcTemplate;
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
public List<Map<String,Object>> db(){
String sql = "select * from user";
List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
return list;

Four . visit

copyright:author[wwz_ henu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130526103496.html