Creating a project

To create a Spring Boot project, let's generate a sample project from https://start.spring.io/. Here, you can add your required dependencies, such as Web, Thymeleaf, JPA , and DevTools. This can be done as follows:

  1. In the drop-down menus at the top, select Maven Project with Kotlin and Spring Boot 2.1.1 (SNAPSHOT):

  1. Give the name of Group, Artifact, Package Name, and add Dependencies. Then hit Generate Project.
  2. Download and unzip the project.
  3. Import the downloaded project into your IDE.

After following these steps, you're ready to use and modify the project. Let's see what's inside this project. You'll find a controller file under src/main/kotlin/{packageName}/AppController.kt.

Here's a piece of code from the controller file:

@RestController
class HtmlController {
@GetMapping("/")
fun blog(model: Model): String {
model["title"] = "Greeting"
return "index"
}
}

Create a class named HtmlController.kt and annotate it with the @RestController annotation to make it a controller class in which we'll deal with web requests. @RestController is the combination of @Controller and @ResponseBody.

Create a function named blog(model: Model) and annotate it with @GetMappingmaps("/"). This will return index.xml as output. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.163.175