JAVA-3541: Move spring-5-mvc into spring-web-modules

This commit is contained in:
Krzysztof Woyke 2021-01-06 11:16:55 +01:00
parent bd75fcb4a4
commit 108522e190
28 changed files with 67 additions and 69 deletions

View File

@ -601,7 +601,6 @@
<module>spring-5</module> <module>spring-5</module>
<module>spring-5-data-reactive</module> <module>spring-5-data-reactive</module>
<module>spring-5-mvc</module>
<module>spring-5-reactive</module> <module>spring-5-reactive</module>
<module>spring-5-reactive-2</module> <module>spring-5-reactive-2</module>
<module>spring-5-reactive-client</module> <module>spring-5-reactive-client</module>
@ -1055,7 +1054,6 @@
<module>spring-5</module> <module>spring-5</module>
<module>spring-5-data-reactive</module> <module>spring-5-data-reactive</module>
<module>spring-5-mvc</module>
<module>spring-5-reactive</module> <module>spring-5-reactive</module>
<module>spring-5-reactive-2</module> <module>spring-5-reactive-2</module>
<module>spring-5-reactive-client</module> <module>spring-5-reactive-client</module>

View File

@ -14,6 +14,7 @@
</parent> </parent>
<modules> <modules>
<module>spring-5-mvc</module>
<module>spring-mvc-basics</module> <module>spring-mvc-basics</module>
<module>spring-mvc-basics-2</module> <module>spring-mvc-basics-2</module>
<module>spring-mvc-basics-3</module> <module>spring-mvc-basics-3</module>

View File

@ -12,8 +12,7 @@
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath> <relativePath>../../parent-boot-2</relativePath>
<!-- lookup parent from repository -->
</parent> </parent>
<dependencies> <dependencies>

View File

@ -1,66 +1,66 @@
package com.baeldung.web; package com.baeldung.web;
import java.util.List; import java.util.List;
import javax.validation.constraints.Max; import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import com.baeldung.model.Foo; import com.baeldung.model.Foo;
import com.baeldung.persistence.FooRepository; import com.baeldung.persistence.FooRepository;
@RestController @RestController
public class FooController { public class FooController {
@Autowired @Autowired
private FooRepository repo; private FooRepository repo;
// API - read // API - read
@GetMapping("/foos/{id}") @GetMapping("/foos/{id}")
@Validated @Validated
public Foo findById(@PathVariable @Min(0) final long id) { public Foo findById(@PathVariable @Min(0) final long id) {
return repo.findById(id).orElse(null); return repo.findById(id).orElse(null);
} }
@GetMapping("/foos") @GetMapping("/foos")
public List<Foo> findAll() { public List<Foo> findAll() {
return repo.findAll(); return repo.findAll();
} }
@GetMapping( value="/foos", params = { "page", "size" }) @GetMapping( value="/foos", params = { "page", "size" })
@Validated @Validated
public List<Foo> findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) { public List<Foo> findPaginated(@RequestParam("page") @Min(0) final int page, @Max(100) @RequestParam("size") final int size) {
return repo.findAll(PageRequest.of(page, size)).getContent(); return repo.findAll(PageRequest.of(page, size)).getContent();
} }
// API - write // API - write
@PutMapping("/foos/{id}") @PutMapping("/foos/{id}")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) { public Foo update(@PathVariable("id") final String id, @RequestBody final Foo foo) {
return foo; return foo;
} }
@PostMapping("/foos") @PostMapping("/foos")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
public void create( @RequestBody final Foo foo) { public void create( @RequestBody final Foo foo) {
if (null == foo || null == foo.getName()) { if (null == foo || null == foo.getName()) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST," 'name' is required"); throw new ResponseStatusException(HttpStatus.BAD_REQUEST," 'name' is required");
} }
repo.save(foo); repo.save(foo);
} }
} }