【发布时间】:2018-08-14 17:54:13
【问题描述】:
我想创建一个链接或另一个 html 元素,它将使用 JPA 和 Thymeleaf 将参数添加到 MySQL 数据库中的表中。我已经创建了一个具有良好 url 的链接(在表中创建一个新参数),但是在单击此元素后 firefox 说:“地址不被理解”但手动输入相同的 url 有效。我需要 index.html 中的那个元素,点击后它会插入到表值中。谢谢。
控制器:
@Controller
public class UserController {
@RequestMapping("/")
public String home() {
return "index";
}
@Autowired
private UserDao userDao;
@RequestMapping("/create")
@ResponseBody
public String create(String email, String name) {
String userId="";
try {
User user = new User(email, name);
userDao.save(user);
userId = String.valueOf(user.getId());
}
catch (Exception exception) {
return "Error creating the user" + exception.toString();
}
return "User succesfully created with id = " + userId;
}
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HomePage</title>
</head>
<body>
<div id="container">
<a href="localhost:8080/create/email=john10234@gmail.com&name=John">Click to
add: ([id], 'john10234@gmail.com', 'John')
</a>
</div>
</body>
</html>
【问题讨论】:
标签: java hibernate jpa spring-boot thymeleaf