Skip to content

Commit adeabdb

Browse files
Add PUT
1 parent 9cddd55 commit adeabdb

8 files changed

Lines changed: 57 additions & 15 deletions

File tree

12_SpringBootWebDevelopment/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

12_SpringBootWebDevelopment/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
<version>5.4.15.Final</version>
4747
</dependency>
4848

49+
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
50+
<dependency>
51+
<groupId>org.thymeleaf</groupId>
52+
<artifactId>thymeleaf</artifactId>
53+
<version>3.0.11.RELEASE</version>
54+
</dependency>
55+
4956
</dependencies>
5057

5158
<build>

12_SpringBootWebDevelopment/src/main/java/main/Storage.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,25 @@
77
import java.util.concurrent.atomic.AtomicInteger;
88

99
public class Storage {
10-
// private static Map<Integer, TodoItem> todoMap = new HashMap<>();
1110
private static ConcurrentHashMap<Integer, TodoItem> todoMap = new ConcurrentHashMap<>();
12-
// private static int currentId = 1;
1311
private static AtomicInteger currentId = new AtomicInteger(1);
1412

15-
public static long addTodoItem(TodoItem item){
16-
// int id = currentId++;
13+
public static long addTodoItem(TodoItem item) {
1714
int id = currentId.getAndIncrement();
1815
item.setId(id);
1916
todoMap.put(id, item);
2017
return id;
2118
}
2219

23-
public static List<TodoItem> getAllTodoItems(){
20+
public static List<TodoItem> getAllTodoItems() {
2421
return new ArrayList<>(todoMap.values());
2522
}
2623

27-
public static TodoItem getItemById(int id){
28-
if(todoMap.containsKey(id)){
29-
return todoMap.get(id);
30-
}
31-
return null;
24+
public static TodoItem getItemById(int id) {
25+
return todoMap.get(id);
3226
}
3327

34-
public static void removeTodoItem(int id){
35-
if(todoMap.containsKey(id)){
36-
todoMap.remove(id);
37-
}
28+
public static void removeTodoItem(int id) {
29+
todoMap.remove(id);
3830
}
3931
}

12_SpringBootWebDevelopment/src/main/java/main/TodoController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package main;
22

33
import main.resoponse.TodoItem;
4+
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.http.HttpStatus;
56
import org.springframework.http.ResponseEntity;
67
import org.springframework.web.bind.annotation.*;
78

89
import javax.validation.Valid;
910
import javax.validation.constraints.NotNull;
1011
import java.util.List;
12+
import java.util.Objects;
1113

1214
@RestController
13-
@RequestMapping(value = "/todo")
15+
@RequestMapping(value = "/")
1416
public class TodoController {
1517

1618
@GetMapping()
@@ -37,4 +39,9 @@ public void deleteItem(@PathVariable("id") int id){
3739
Storage.removeTodoItem(id);
3840
}
3941

42+
@PutMapping("/{id}")
43+
public void update(@PathVariable("id") int id, String title){
44+
Storage.getItemById(id).setTitle(Objects.requireNonNull(title));
45+
}
46+
4047
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>12_SpringBootWebDev</title>
6+
</head>
7+
<body>
8+
9+
</body>
10+
</html>
-122 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>12_SpringBootWebDev</title>
6+
</head>
7+
<body>
8+
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)