Untitled

Untitled

Untitled

Database 생성

create table fruit(
	id bigint auto_increment,
	name varchar(25),
	warehousingDate date,
	price int,
	status ENUM('SOLD', 'NOT_SOLD') DEFAULT 'NOT_SOLD',
	primary key (id)
);	

문제 1

DTO

public class FruitCreateRequest {

    private String name;
    private LocalDate warehousingDate;
    private long price;

    ... 생성자, getter 
}

Controller

@PostMapping("/api/v1/fruit")
    public void saveFruit(@RequestBody FruitCreateRequest request){
        String sql = "INSERT INTO fruit (name, warehousingDate, price) VALUES (?, ?, ?)";
        jdbcTemplate.update(sql, request.getName(), request.getWarehousingDate(), request.getPrice());
    }

결과

Untitled

Untitled