Difference between revisions of "Java: Spring Boot"

From RHS Wiki
Jump to navigation Jump to search
m
Tag: visualeditor
m
Tag: visualeditor
Line 41: Line 41:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== Spring Boot Starter Projects ==
 +
Found at [https://start.spring.io Spring Initializr] Under dependencies
 +
 +
Web Application: Spring Boot Starter Web
 +
 +
REST API: Spring Boot Starter Web
 +
 +
Talk to database using JPA: Spring Boot Starter Data JPA
 +
 +
Talk to database using JDBC: Spring Boot Starter Data JDBC
 +
 +
Secure your web application or REST API: Spring Boot Starter Security
 
[[Category:Java]]
 
[[Category:Java]]

Revision as of 14:04, 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"));
    }
}

Spring Boot Starter Projects

Found at Spring Initializr Under dependencies

Web Application: Spring Boot Starter Web

REST API: Spring Boot Starter Web

Talk to database using JPA: Spring Boot Starter Data JPA

Talk to database using JDBC: Spring Boot Starter Data JDBC

Secure your web application or REST API: Spring Boot Starter Security