반응형
SMALL
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>3.0.3</version>
</dependency>
서버를 수동으로 돌리지 않고 저장만 하면 됌
package com.in28minutes.springboot.learnspringboot;
import java.util.Arrays;
import java.util.List; // Import List class
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CourseController {
@RequestMapping("/courses") // Correct the URL path to "/courses"
public List<Course> retrieveAllCourses(){
return Arrays.asList(
new Course(1, "id", "in28minutes"),
new Course(2, "name", "in28minutes"),
new Course(3, "jh", "in28minutes"),
new Course(4, "jh123123", "in28minutes")
);
}
}
@RestController
@RequestMapping
import 주의
package com.in28minutes.springboot.learnspringboot;
public class Course {
private long id;
private String name;
private String author;
//Constructor
public Course(long id, String name, String author) {
super();
this.id = id;
this.name = name;
this.author = author;
}
//getters
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
//toString
@Override
public String toString() {
return "Course [id=" + id + ", name=" + name + ", author=" + author + "]";
}
}
반응형
LIST
'Spring > Spring Boot' 카테고리의 다른 글
@RestController, @RequestMapping("/courses") (0) | 2023.09.19 |
---|---|
trace, debug, info, warning, error, off (0) | 2023.09.19 |
Bufferread , Scanner 비교 (0) | 2023.08.31 |
[JAVA] Interger와 int의 차이점, == 연산과 equals()의 차이점, Array 와 Array List 차이점 정리 (0) | 2023.08.31 |
JDBC활용하여 데이터 입력, 삭제, 조회 (0) | 2023.08.27 |