Learn Spring Boot 1

Spring initialization

  • spring-boot-starter-web
  • spring-boot-starter-data-jpa
  • spring-boot-devtools
  • mysql-connector-java
  • lombok

Connect to database

in the resource/application.properties, we can config the hibernate connection for mysql

1
2
3
4
5
6
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql= true

Simple API

To build a simple api, we need to add two annotaion to the main

  • RestController
  • @GetMapping/@PostMapping/ others
1
2
3
4
5
6
7
8
9
10
11
12
13
@SpringBootApplication
@RestController
public class PpfaSpringApplication {

public static void main(String[] args) {
SpringApplication.run(PpfaSpringApplication.class, args);
}

@GetMapping
public String hello() {
return "Hello World";
}
}
Author

Elliot

Posted on

2022-06-02

Updated on

2023-05-07

Licensed under