0
我用MySQL数据库设置了Spark框架和thymeleaf。我无法将要删除的用户的ID传递到我的应用程序的后端。从Spark数据库中删除用户和MySQL中的Thymeleaf
后端
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,我希望它火花框架注册删除方法,有什么办法可以完成这个?