我已经用 MySQL 数据库设置了 spark 框架和 thymeleaf。我无法将要删除的用户 ID 传递到我的应用程序的后端。
后端
get("/delete", (rq, rs) -> {
map.put("lista", studentService.getAllStudents());
return thymeleafTemplateEngine.render(new ModelAndView(map,"delete"));});
delete("/delete:id", (rq, rs) -> {
studentService.deleteStudent(rq.params(":id"));
return "Korisnik uspesno izbrisan iz baze.";
});
服务
public void deleteStudent(String id){
sql = "DELETE FROM student WHERE student_id="+id;
con = ConnectionManager.getConnection();
try{
stmt = con.createStatement();
stmt.executeUpdate(sql);
} catch (SQLException e){
e.printStackTrace();
}
}
前端
<form th:method="delete">
<input th:name="id" type="text" placeholder="Id korisnika">
<button type="submit">Submit</button>
</form>
这是从 thymeleaf 模板http://localhost:4567/delete?id=15传递的 url,我希望它通过 spark 框架的 delete 方法注册,有什么方法可以实现吗?