Skip to content

Commit 5758048

Browse files
committed
Html Structure
1 parent 2d0095d commit 5758048

File tree

8 files changed

+103
-54
lines changed

8 files changed

+103
-54
lines changed

src/main/java/com/itacademy/CrudEmpleats/controller/ControllerEmployees.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,43 @@ public class ControllerEmployees {
2121
@Autowired
2222
private EmployeeRepository repositori;
2323

24-
24+
/*
2525
// Temporalment redirigim a la llista d'empleats
2626
@GetMapping("/")
2727
void start(HttpServletResponse reponse) throws IOException {
2828
reponse.sendRedirect("/Empleat");
29-
}
29+
}*/
3030

3131
// Crear nou empleat
32-
@PostMapping( "/Empleat")
32+
@PostMapping( "/EmpleatList")
3333
@ResponseStatus(HttpStatus.CREATED) // 201
3434
public Employee addEmployee(@RequestBody Employee employee) {
3535
repositori.addEmployee(employee);
3636
return employee;
3737
}
3838

3939
// Retorna una llista JSon d'empleats
40-
@GetMapping("/Empleat")
40+
@GetMapping("/EmpleatList")
4141
public List<Employee> allEmployees() {
4242
return repositori.getAllEmployees();
4343
}
4444

4545
// Busca un empleat per Id
46-
@GetMapping("/Empleat/{id}")
46+
@GetMapping("/EmpleatList/{id}")
4747
public Employee getFirstEmployee(@PathVariable("id") int id) {
4848
return repositori.getEmployeeById(id);
4949
}
5050

5151
// Actualitzar Empleat
52-
@PutMapping("/Empleat/{id}")
52+
@PutMapping("/EmpleatList/{id}")
5353
@ResponseStatus(HttpStatus.ACCEPTED) // 202
5454
public Employee updateEmployee(@RequestBody Employee employee, @PathVariable("id") int id) {
5555
repositori.updateEmployee(employee,id);
5656
return repositori.getEmployeeById(id);
5757
}
5858

5959
// Eliminar Empleat
60-
@DeleteMapping("/Empleat/{id}")
60+
@DeleteMapping("/EmpleatList/{id}")
6161
@ResponseStatus(HttpStatus.ACCEPTED) // 202
6262
public String deleteEmployee(@PathVariable("id") int id) {
6363
repositori.deleteEmployee(id);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.itacademy.CrudEmpleats.controller;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
6+
@Controller
7+
public class ControllerWeb {
8+
/*
9+
* Controlador d'accés html
10+
*/
11+
12+
@GetMapping("/index")
13+
public String goIndex() {
14+
return "index";
15+
}
16+
17+
@GetMapping("/BodyHeader")
18+
public String bodyHeader() {
19+
return "BodyHeader";
20+
}
21+
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11

2+
spring.mvc.static-path-pattern=/content/**

src/main/resources/templates/Fragments/BodyHeader.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/resources/templates/Fragments/head.html

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
4+
<script>
5+
$(document).ready(function() {
6+
$("#BodyHeader").load("BodyHeader.html", function() {
7+
alert("Load was performed.");
8+
});
9+
});
10+
</script>
11+
12+
</head>
13+
<body>
14+
15+
</body>
16+
</html>
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<!DOCTYPE html>
2-
<html xmlns:th="http://thymeleaf.org">
2+
<html>
33
<head>
4-
<th:block th:include="Fragments/head :: head"></th:block>
5-
4+
<meta charset="UTF-8">
5+
<title>Spring - Crud Empleats</title>
66
</head>
77
<body>
8-
<div class="container">
9-
<div th:insert="Fragments/BodyHeader :: div"></div>
10-
11-
12-
<label>Introduir un nou empleat:</label><br><br>
13-
14-
<form action="/" method="post">
15-
Nom: <input type=text name=><br><br>
16-
Cognom: <input type=text name=cognom><br><br>
17-
18-
<input type=submit name="submit" value="Nou Empleat">
19-
20-
21-
</form>
8+
<div class="container"></div>
9+
<div>
10+
<H4>Modificar empleat</H4>
2211
</div>
12+
<div>
13+
<div class="container">
14+
<div th:insert="Fragments/BodyHeader :: div"></div>
15+
<form action="/" method="post">
16+
#: <input type="text" name=id>
17+
Nom: <input type=text name=name>
18+
Càrreg: <input type=text name=job>
19+
<br><br>
20+
<input type=submit name="submit" value="Modificar">
21+
<input type=submit name="submit" value="Cancellar">
22+
</form>
23+
</div>
2324
</body>
25+
2426
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Spring - Crud Empleats</title>
6+
</head>
7+
<body>
8+
<div class="container"></div>
9+
<div>
10+
<H4>Empleats</H4><button type="submit">Nou Empleat</button>
11+
</div>
12+
<div>
13+
<table id="employeeTable" border="1">
14+
<tr>
15+
<th>#</th>
16+
<th>Nom</th>
17+
<th>Càrreg</th>
18+
<th>Salari</th>
19+
<th>Accions</th>
20+
</tr>
21+
<tbody>
22+
<tr>
23+
<th>0</th>
24+
<td>Gerard</td>
25+
<td>Programador Junior</td>
26+
<td>puiglatorre@gmail.com</td>
27+
<td>
28+
<button type="submit">Modificar</button>
29+
<button type="submit">Eliminar</button>
30+
</td>
31+
</tr>
32+
33+
</tbody>
34+
</table>
35+
</div>
36+
</div>
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)