This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #39 and fix clean controller generator
- Loading branch information
Showing
12 changed files
with
140 additions
and
27 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
sample/src/main/java/com/example/controller/ProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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("/product") | ||
public class ProductController { | ||
|
||
@GetMapping | ||
public String index() { | ||
return "product/index"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!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>Product</h1> | ||
<hr /> | ||
</div> | ||
</body> | ||
</html> |
34 changes: 16 additions & 18 deletions
34
...erate/src/main/java/br/com/generate/java/command/controller/ControllerCleanGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
package br.com.generate.java.command.controller; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import br.com.generate.Layers; | ||
import br.com.generate.ReadTemplateFile; | ||
|
||
import br.com.generate.ReadScaffoldInfo; | ||
public class ControllerCleanGenerator extends ReadTemplateFile { | ||
|
||
public class ControllerCleanGenerator extends ReadScaffoldInfo { | ||
|
||
public ControllerCleanGenerator(String className) throws IOException { | ||
generate(className); | ||
} | ||
@Override | ||
public String getLayer() { | ||
return Layers.CONTROLLER; | ||
} | ||
|
||
@Override | ||
protected String operationGenerate(String javaStrings, String nameClass, String parameters) { | ||
return javaStrings.replace("${package}", getPackage() + ".controller") | ||
.replace("${path}", nameClass.toLowerCase()) | ||
.replace("${className}", nameClass); | ||
} | ||
|
||
public void generate(String className) throws IOException { | ||
File javaTemplateFile = new File(getUserDir() + "/src/main/resources/templates/java/controller/template-clean-controller.txt"); | ||
String javaStrings = FileUtils.readFileToString(javaTemplateFile); | ||
|
||
javaStrings = javaStrings.replace("${package}", getPackage() + ".controller"); | ||
javaStrings = javaStrings.replace("${className}", className); | ||
|
||
File newJavaFile = new File(getPathPackage() + "controller/" + className + "Controller.java"); | ||
FileUtils.writeStringToFile(newJavaFile, javaStrings); | ||
System.out.println("create " + getPathPackage() + className + "Controller.java"); | ||
public static void main(String[] args) throws IOException { | ||
new ControllerCleanGenerator().generate("Credential", null, "template-clean-controller.txt"); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
spring-boot-generate/src/main/java/br/com/generate/thymeleaf/ThymeleafCleanGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package br.com.generate.thymeleaf; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
public class ThymeleafCleanGenerator extends AbstractThymeleafGenerate { | ||
|
||
public void index(String className, String parameters) throws IOException { | ||
String htmlString = IOUtils.toString(getClass().getResourceAsStream("/templates/template-clean-index.html"), null); | ||
String template = "layout"; | ||
String classNameParam = className; | ||
String paramClassName = className.toLowerCase(); | ||
String pathUrl = "/" + className.toLowerCase() + "s"; | ||
String eachParam = "list" + className; | ||
|
||
htmlString = htmlString.replace("${template}", template); | ||
htmlString = htmlString.replace("${className}", classNameParam); | ||
htmlString = htmlString.replace("paramClassName", paramClassName); | ||
htmlString = htmlString.replace("eachParam", eachParam); | ||
htmlString = htmlString.replace("url_path", pathUrl); | ||
|
||
File newHtmlFile = new File(getUserDir() + "/src/main/resources/templates/" + className.toLowerCase() + "/index.html"); | ||
|
||
FileUtils.writeStringToFile(newHtmlFile, htmlString); | ||
System.out.println("create /src/main/resources/templates/" + className.toLowerCase() + "/index.html"); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...-boot-generate/src/main/resources/templates/java/controller/template-clean-controller.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package ${package}; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/${path}") | ||
public class ${className}Controller { | ||
|
||
@GetMapping | ||
public String index() { | ||
return "${path}/index"; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
spring-boot-generate/src/main/resources/templates/template-clean-index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org" | ||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" | ||
layout:decorator="${template}"> | ||
<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>${className}</h1> | ||
<hr /> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...g-scaffold-cli/src/main/resources/templates/java/controller/template-clean-controller.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package ${package}; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/${path}") | ||
public class ${className}Controller { | ||
|
||
@GetMapping | ||
public String index() { | ||
return "${path}/index"; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
spring-scaffold-cli/src/main/resources/templates/template-clean-index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org" | ||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" | ||
layout:decorator="${template}"> | ||
<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>${className}</h1> | ||
<hr /> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters