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,我希望它火花框架註冊刪除方法,有什麼辦法可以完成這個?