Difference between revisions of "Java: Spring Boot"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) m Tag: visualeditor |
Rafahsolis (talk | contribs) m Tag: visualeditor |
||
| Line 1: | Line 1: | ||
| − | Create microservices | + | Create microservices<syntaxhighlight lang="java"> |
| + | import java.util.Arrays; | ||
| + | import java.util.List; | ||
| + | import org.springframework.web.bind.annotation.RestController; | ||
| + | import org.springframework.web.bind.annotation.GetMapping; | ||
| + | |||
| + | public class Course { | ||
| + | private long id; | ||
| + | private String name; | ||
| + | private String author; | ||
| + | |||
| + | public Course(long id, String name, String author){ | ||
| + | super(); | ||
| + | this.id = id; | ||
| + | this.name = name; | ||
| + | this.author = author; | ||
| + | } | ||
| + | |||
| + | public String toString() { | ||
| + | return "Course [id=" + id + ", name= " + name + ", author=" + author + " ]"; | ||
| + | } | ||
| + | |||
| + | public long getId() { | ||
| + | return id; | ||
| + | } | ||
| + | public String getName() { | ||
| + | return name; | ||
| + | } | ||
| + | public String getAuthor() { | ||
| + | return author; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | @RestController | ||
| + | public class CourseController { | ||
| + | @GetMapping("/courses") | ||
| + | public List<Course> getAllCourses(){ | ||
| + | return Arrays.asList(new Course(1, "Learn microservices", "in28minutes")); | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
[[Category:Java]] | [[Category:Java]] | ||
Revision as of 13:55, 30 April 2022
Create microservices
import java.util.Arrays;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
public class Course {
private long id;
private String name;
private String author;
public Course(long id, String name, String author){
super();
this.id = id;
this.name = name;
this.author = author;
}
public String toString() {
return "Course [id=" + id + ", name= " + name + ", author=" + author + " ]";
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
}
@RestController
public class CourseController {
@GetMapping("/courses")
public List<Course> getAllCourses(){
return Arrays.asList(new Course(1, "Learn microservices", "in28minutes"));
}
}