From ffcdceb05c443f657f2925e61ae4197a91044a9f Mon Sep 17 00:00:00 2001 From: Paul W Bennett Date: Sun, 30 Apr 2017 15:05:45 -0500 Subject: [PATCH] spring mvc stuff --- .../repository/0.0.3/compile-pom.xml | 13 ++++++++- .../src/main/resources/templates/hello.html | 28 +++++++++++++++++++ .../webapp/WEB-INF/classes/description.html | 8 +++--- .../springboot/web/LibertyMVController.java | 17 +++++++++++ ...roller.java => LibertyRestController.java} | 6 ++-- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 starter-microservice-springboot-web/src/main/resources/templates/hello.html create mode 100644 starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyMVController.java rename starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/{LibertyHelloController.java => LibertyRestController.java} (85%) diff --git a/starter-microservice-springboot-web/repository/0.0.3/compile-pom.xml b/starter-microservice-springboot-web/repository/0.0.3/compile-pom.xml index c0f73d6..d716658 100644 --- a/starter-microservice-springboot-web/repository/0.0.3/compile-pom.xml +++ b/starter-microservice-springboot-web/repository/0.0.3/compile-pom.xml @@ -35,7 +35,18 @@ spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-thymeleaf + 1.3.0.RELEASE + + + org.springframework.boot + spring-boot-starter-tomcat + + - \ No newline at end of file + diff --git a/starter-microservice-springboot-web/src/main/resources/templates/hello.html b/starter-microservice-springboot-web/src/main/resources/templates/hello.html new file mode 100644 index 0000000..d7ae26f --- /dev/null +++ b/starter-microservice-springboot-web/src/main/resources/templates/hello.html @@ -0,0 +1,28 @@ + + + + + + Liberty App Accelerator MVC Sample + + + +

+

Welcome to your Liberty Spring MVC Application

+

Thanks for generating this project using the app accelerator.

+ + diff --git a/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html index fa83c6d..2246d5d 100644 --- a/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html @@ -14,12 +14,12 @@ limitations under the License. -->
-

Spring Boot with Spring MVC

-

Inside the project there is a application.springboot.web package - containing two classes:

+

Spring Boot with Spring MVC and REST controllers

+

Inside the project there is a application.springboot.web package containing these classes:

  • SpringBootLibertyApplication: The entry point for the SpringBoot application.
  • -
  • LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb
  • +
  • LibertyMVController: A Spring MVC endpoint which you can access at /springbootmvc
  • +
  • LibertyRESTController: A Spring REST endpoint which you can access at /springbootrest

There is also a test class named it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyMVController.java b/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyMVController.java new file mode 100644 index 0000000..ac33e91 --- /dev/null +++ b/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyMVController.java @@ -0,0 +1,17 @@ +package application.springboot.web; + +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 LibertyMVController { + + @RequestMapping("/springbootmvc") + public String greeting(@RequestParam(value="entity", required=false, defaultValue="World") String entity, Model model) { + model.addAttribute("entity", entity); + return "hello"; + } + +} diff --git a/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyHelloController.java b/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyRestController.java similarity index 85% rename from starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyHelloController.java rename to starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyRestController.java index aff3e2f..7e5583d 100644 --- a/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyHelloController.java +++ b/starter-microservice-springboot-web/src/main/webapp/sample/src/main/java/application/springboot/web/LibertyRestController.java @@ -19,11 +19,11 @@ import org.springframework.web.bind.annotation.RestController; @RestController -public class LibertyHelloController { +public class LibertyRestController { - @RequestMapping("/springbootweb") + @RequestMapping("/springbootrest") public String hello() { - return "Hello from Spring Boot MVC running on Liberty!"; + return "Hello from your Spring Boot Rest Controller running on Liberty!"; } } \ No newline at end of file