Skip to content
José Vieira Neto edited this page Dec 15, 2017 · 8 revisions

Commands

Scaffold

There are several commands the main one is the scaffold where it generates for you the model, repository, service, controler and the view with thymeleaf.

When running spring scaffold -n "User" -p "name: String email: String"

you will see.

created src/main/java/com/example/model/UserModel.java
created src/main/java/com/example/repository/UserRepository.java
created src/main/java/com/example/service/UserService.java
created src/main/java/com/example/controller/UserController.java
created src/main/resources/layout.html
created src/main/resources/templates/user/index.html
created src/main/resources/templates/user/form.html
created src/main/resources/templates/user/show.html

with this simple command you already have a complete crud (create, read, update, delete).

it is also possible to generate a scaffold for api rest:

spring scaffold -n "User" -p "name: String email: String" -r "true"

Controller

Another very common command is the spring controller -n "Home"

Output:

created src/main/java/com/example/controller/HomeController.java
created src/main/resources//templates/home/index.html

Files generated:

HomeController.java

package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/home")
public class HomeController {

	@GetMapping
	public String index() {
	    return "home/index";
	}

}

home.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	  layout:decorator="layout">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="" />
    <meta name="author" content="" />
</head>
<body>

	<div layout:fragment="content">
	    <h1>Home</h1>
	    <hr />
	</div>
</body>
</html>

Model

command spring model -n "User" -p "name:String email:String"

Output:

Clone this wiki locally