Merge pull request #10397 from kwoyke/JAVA-3541

JAVA-3541: Move spring-5-mvc into spring-web-modules
This commit is contained in:
Loredana Crusoveanu 2021-01-06 17:09:53 +02:00 committed by GitHub
commit 66b453758b
28 changed files with 67 additions and 69 deletions

View File

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

View File

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

View File

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

View File

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