-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added route for web-based controllers
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
var util = require('util'); | ||
var yeoman = require('yeoman-generator'); | ||
|
||
var RestGenerator = module.exports = function RestGenerator(args, options, config) { | ||
yeoman.generators.Base.apply(this, arguments); | ||
}; | ||
|
||
util.inherits(RestGenerator, yeoman.generators.Base); | ||
|
||
RestGenerator.prototype.askFor = function askFor() { | ||
var cb = this.async(); | ||
|
||
var prompts = [ | ||
{ | ||
type: 'string', | ||
name: 'packageName', | ||
message: '(1/4) Package name:', | ||
default: this.config.get('packageName') | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'viewName', | ||
message: '(2/4) Name for your view:', | ||
default: 'page' | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'controllerName', | ||
message: '(3/4) Name for your controller:', | ||
default: 'MyController' | ||
}, | ||
{ | ||
type: 'string', | ||
name: 'controllerPath', | ||
message: '(4/4) Path to Controller:', | ||
default: '/hello-world' | ||
} | ||
] | ||
|
||
this.prompt(prompts, function (props) { | ||
this.packageName = props.packageName; | ||
this.viewName = props.viewName; | ||
this.controllerName = props.controllerName; | ||
this.controllerPath = props.controllerPath; | ||
cb(); | ||
}.bind(this)); | ||
|
||
}; | ||
|
||
RestGenerator.prototype.files = function app() { | ||
var packageFolder = this.packageName.replace(/\./g, '/'); | ||
var controllersDir = 'src/main/java/' + packageFolder + '/controller'; | ||
var viewsDir = 'src/main/resources/templates'; | ||
|
||
this.mkdir(controllersDir); | ||
this.mkdir(viewsDir); | ||
|
||
this.template('Controller.java', controllersDir + '/' + this.controllerName + '.java'); | ||
this.template('view.html', viewsDir + '/' + this.viewName + '.html'); | ||
|
||
this.config.set('packageName', this.packageName); | ||
}; |
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,17 @@ | ||
package <%= packageName %>.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
public class <%= controllerName %> { | ||
|
||
@RequestMapping("<%= controllerPath %>") | ||
public String process(@RequestParam(value = "content", required = false, defaultValue = "content") String content, Model model) { | ||
model.addAttribute("content", content); | ||
return "<%= viewName %>"; | ||
} | ||
|
||
} |
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,9 @@ | ||
<!DOCTYPE HTML> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
</head> | ||
<body> | ||
<p th:text="${content}" /> | ||
</body> | ||
</html> |