반응형
SMALL
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 + "]";
}
}
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")
);
}
}
반응형
LIST
'Spring > Spring Boot' 카테고리의 다른 글
h2콘솔 실행하기 (0) | 2023.09.19 |
---|---|
@ConfigurationProperties (0) | 2023.09.19 |
trace, debug, info, warning, error, off (0) | 2023.09.19 |
devtools (0) | 2023.09.16 |
Bufferread , Scanner 비교 (0) | 2023.08.31 |