Skip to content
José Vieira Neto edited this page Aug 5, 2019 · 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"

This command generates all crud operation

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).

see example: Sample

Individual Generate

Are simple and clean generators.

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 "Admin" -p "name:String email:String"

Output:

created src/main/java/com/example/model/AdminModel.java

@Entity
@Data
public class AdminModel {
	
	 @Id @GeneratedValue(strategy = GenerationType.AUTO)
	 private Integer id;
	 private String name;
	 private String email;
}

Repository

command spring repository -n "Admin"

Output:

created src/main/java/com/example/repository/AdminRepository.java

@Repository
public interface AdminRepository {  //extends JpaRepository<?, ?> {
}

Service

command spring service -n "Admin"

Output:

created src/main/java/com/example/service/AdminService.java

@Service
@Transactional(readOnly = true)
public class AdminService {

}
Clone this wiki locally