diff --git a/spring-boot-modules/spring-boot-mvc-4/README.md b/spring-boot-modules/spring-boot-mvc-4/README.md index a05aa3c7b9..c6820ce930 100644 --- a/spring-boot-modules/spring-boot-mvc-4/README.md +++ b/spring-boot-modules/spring-boot-mvc-4/README.md @@ -8,4 +8,3 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) - [Configure a Spring Boot Web Application](https://www.baeldung.com/spring-boot-application-configuration) - [A Guide to Spring in Eclipse STS](https://www.baeldung.com/eclipse-sts-spring) -- More articles: [[<-- Prev]](/spring-boot-modules/spring-boot-mvc-3) diff --git a/spring-boot-modules/spring-boot-mvc-4/pom.xml b/spring-boot-modules/spring-boot-mvc-4/pom.xml index 7d4d6e3d0c..5b58b326ab 100644 --- a/spring-boot-modules/spring-boot-mvc-4/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-4/pom.xml @@ -1,13 +1,14 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 spring-boot-mvc-4 spring-boot-mvc-4 jar Module For Spring Boot MVC Web - + com.baeldung.spring-boot-modules spring-boot-modules @@ -19,13 +20,27 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-thymeleaf + org.springframework.boot spring-boot-starter-validation org.springframework.boot - spring-boot-starter-thymeleaf + spring-boot-devtools + true + + + io.springfox + springfox-boot-starter + ${spring.fox.version} + + + com.fasterxml.jackson.core + jackson-databind org.springframework.boot @@ -42,4 +57,23 @@ + + + + org.springframework.boot + spring-boot-maven-plugin + + ${start-class} + JAR + + + + + + + + 3.0.0 + com.baeldung.springboot.swagger.ArticleApplication + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java similarity index 91% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java index 568d31e8bc..8be380baa0 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/ArticleApplication.java @@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; @@ -12,6 +13,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableSwagger2 +@EnableWebMvc public class ArticleApplication { public static void main(String[] args) { diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java similarity index 91% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java index 96812e367a..c4336a7cfe 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/controller/ArticlesController.java @@ -21,7 +21,7 @@ public class ArticlesController { } @PostMapping("") - public void addArticle(@RequestBody Article article) { + public void addArticle(@ModelAttribute Article article) { articleService.addArticle(article); } diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/model/Article.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/model/Article.java similarity index 97% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/model/Article.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/model/Article.java index 6512b4e1a7..f6318c04b3 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/model/Article.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/model/Article.java @@ -15,6 +15,7 @@ public class Article { //@ApiModelProperty(hidden = true) //@ApiParam(hidden = true) //@ApiModelProperty(readOnly = true) + @ApiParam(hidden = true) private int id; private String title; private int numOfWords; diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java similarity index 99% rename from spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java rename to spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java index 04f6e6c6e3..3fd0279988 100644 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/java/com/baeldung/springboot/swagger/service/ArticleService.java @@ -20,6 +20,6 @@ public class ArticleService { article.setId(articles.size() + 1); articles.add(article); } - + } diff --git a/spring-boot-modules/spring-boot-mvc-4/src/main/resources/static/index.html b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/static/index.html new file mode 100644 index 0000000000..9f55d12685 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-4/src/main/resources/static/index.html @@ -0,0 +1 @@ +Welcome to Baeldung \ No newline at end of file