我目前正在學習Spring,並且在不同的例子中不斷碰到這個問題,但我沒有發現任何解釋的任何地方{@} @RequestMapping(value =「/ delete/{id}」)中的{id}是什麼意思
我還發現
return "redirect:/delete/{id}"
我明白ID是一個變量,但它有什麼作用。正是從這個例子http://www.javainterviewpoint.com/spring-mvc-crud-example-mysql/
控制器
@RequestMapping(value = "/delete/{id}")
public ModelAndView deleteEmployee(@ModelAttribute("employee") Employee employee,@PathVariable("id") int id)
{
employeeDAO.deleteEmployee(id);
return new ModelAndView("redirect:/employees");
}
型號
package com.javainterviewpoint;
import java.io.Serializable;
public class Employee implements Serializable
{
private static final long serialVersionUID = -1280037900360314186L;
private Integer id;
private String name;
private Integer age;
private String dept;
public Employee()
{
super();
}
public Employee(Integer id, String name, Integer age, String dept)
{
super();
this.id = id;
this.name = name;
this.age = age;
this.dept = dept;
}
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
兩者
@RequestMapping(value = "/delete/{id}")
和
@RequestMapping(value = "/delete")
之間的區別
您所採取的閱讀[參考指南](時間https://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates)? –
我沒有意識到這一點。謝謝 – Adi