我目前正在学习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