File tree Expand file tree Collapse file tree 4 files changed +16
-28
lines changed
java/com/itacademy/CrudEmpleats Expand file tree Collapse file tree 4 files changed +16
-28
lines changed Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
- <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
3
4
xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
4
5
<modelVersion >4.0.0</modelVersion >
5
6
<parent >
6
7
<groupId >org.springframework.boot</groupId >
7
8
<artifactId >spring-boot-starter-parent</artifactId >
8
9
<version >2.4.3</version >
9
- <relativePath /> <!-- lookup parent from repository -->
10
+ <relativePath /> <!-- lookup parent from repository -->
10
11
</parent >
11
12
<groupId >com.itacademy</groupId >
12
13
<artifactId >CrudEmpleats</artifactId >
17
18
<java .version>15</java .version>
18
19
</properties >
19
20
<dependencies >
21
+ <dependency >
22
+ <groupId >org.springframework.boot</groupId >
23
+ <artifactId >spring-boot-starter-validation</artifactId >
24
+ </dependency >
20
25
<dependency >
21
26
<groupId >org.springframework.boot</groupId >
22
27
<artifactId >spring-boot-starter-thymeleaf</artifactId >
Original file line number Diff line number Diff line change 2
2
3
3
import java .util .List ;
4
4
5
+ import javax .validation .Valid ;
5
6
6
7
import org .springframework .beans .factory .annotation .Autowired ;
7
8
import org .springframework .http .HttpStatus ;
@@ -22,7 +23,7 @@ public class ControllerEmployees {
22
23
// Crear nou empleat
23
24
@ PostMapping ( "/EmployeeList" )
24
25
@ ResponseStatus (HttpStatus .CREATED ) // 201
25
- public void addEmployee (@ RequestBody Employee employee ) {
26
+ public void addEmployee (@ Valid @ RequestBody Employee employee ) {
26
27
repositori .addEmployee (employee );
27
28
28
29
}
@@ -42,7 +43,7 @@ public Employee getFirstEmployee(@PathVariable("id") int id) {
42
43
// Actualitzar Empleat
43
44
@ PutMapping ("/EmployeeList/{id}" )
44
45
@ ResponseStatus (HttpStatus .ACCEPTED ) // 202
45
- public Employee updateEmployee (@ RequestBody Employee employee , @ PathVariable ("id" ) int id ) {
46
+ public Employee updateEmployee (@ Valid @ RequestBody Employee employee , @ PathVariable ("id" ) int id ) {
46
47
repositori .updateEmployee (employee ,id );
47
48
return repositori .getEmployeeById (id );
48
49
}
Original file line number Diff line number Diff line change 1
1
package com .itacademy .CrudEmpleats .domain ;
2
2
3
+ import javax .validation .constraints .NotBlank ;
4
+ import javax .validation .constraints .NotNull ;
5
+
3
6
public class Employee {
4
7
8
+ @ NotNull
5
9
private int id ;
10
+ @ NotBlank
6
11
private String name ;
12
+ @ NotBlank
7
13
private String job ;
8
14
private double salary ;
9
15
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments