Spring MVC 请求映射搜索参数上最接近的匹配。今天我们刚刚遇到了一个很好的例子,为什么这个当前的实现是有问题的。我们有两个功能:
@RequestMapping(method = Array[RequestMethod](RequestMethod.DELETE), params = Array[String]("lastName", "firstName"), produces = Array[String]("application/json"))
def deletePersons1(request: HttpServletRequest, @RequestParam("lastName") lastName: String, @RequestParam("firstName") acref: String)
@RequestMapping(method = Array[RequestMethod](RequestMethod.DELETE), params = Array[String]("lastName", "birthDate"), produces = Array[String]("application/json"))
def deletePersons2(request: HttpServletRequest, @RequestParam("lastName") lastName: String, @RequestParam("birthDate") birthDate: Date)
http请求是:
DELETE http://host:port/deletePersons?lastName=smith&firstName=john&birthDate=08-10-2015
用户只想删除 Smith,John 并且还认为他们可以添加出生日期。但是由于第一个函数没有得到日期并且用户犯了一个错误并在那里输入了一个日期,所以在我们的例子中,使用了第二个函数,因为它最接近匹配。我仍然不知道为什么是第二个而不是第一个。
结果是所有姓史密斯、出生在……的人都被删除了。
这是一个真正的问题!因为我们只想删除一个特定的人,但最终删除了许多其他人。
有什么解决办法吗?