Dzień dobry,
Próbuję zrobić prosty przycisk, który będzie zapisywac wpisane słowa z pola tekstowego do listy, a po przejsciu do /results wyswietli mi te wprowadzone dane.
main.html:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<BODY>
<form action="#" th:action="@{/}" th:object="${achievement}" method="post">
<input type="text" th:field="*{name}"/>
<input type="submit" name="action" value="save" />
<input type="submit" name="action" value="show" />
</form>
</BODY>
</html>
@Entity
public class Achievement {
@Id
@GeneratedValue
private Long id;
private String token;
@GeneratedValue
@Column(nullable = false)
private String name;
private String description;
public Achievement(String name) {
this.name = name;
}
@ManyToOne
private Game game;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Game getGame() {
return game;
}
public void setGame(Game game) {
this.game = game;
}
}
@Controller
@RequestMapping("/")
public class Controler {
@Autowired
private Manager manager;
@GetMapping("/")
public String greeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "main";
}
@RequestMapping(value="/", method = RequestMethod.POST)
public String greetingSubmit(@ModelAttribute Achievement achievement, HttpSession session) {
String names = (String) session.getAttribute("names");
if (names == null) {
session.setAttribute("names", names);
}
manager.getAchievementList().add(new Achievement(names));
return "main";
}
}
@RestController
public class ResControler {
@Autowired
private Manager manager;
@GetMapping("/results")
public List<Achievement> achievementList() {
return manager.getAchievementList();
}
}
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Jun 07 13:12:04 CEST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "main" - line 10, col 24)
Co jest źle?