-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathToDoList.java
41 lines (34 loc) · 1.24 KB
/
ToDoList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.devhow.htmxdemo;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@Controller
@RequestMapping("/public/todo")
public class ToDoList {
@GetMapping
public String start(Model model) {
model.addAttribute("now", new Date().toInstant());
model.addAttribute("item", "Get Stuff Done");
return "todo";
}
@DeleteMapping(path = "/delete", produces = MediaType.TEXT_HTML_VALUE)
@ResponseBody
public String delete() {
return "";
}
/**
* Thymeleaf will let you use the fragment syntax in a controller, as shown below.
* https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#defining-and-referencing-fragments
*/
@PostMapping(path = "/create")
public String create(@RequestParam("new-todo") String todo, Model model) {
model.addAttribute("item", todo);
// Currently, IntelliJ doesn't recognize a Thymeleaf fragment returned in a controller.
// https://youtrack.jetbrains.com/issue/IDEA-276625
//
//noinspection SpringMVCViewInspection
return "todo :: todo";
}
}