PropertiesMethodNameResolver , гибкий мультиакционный контроллер methodnameresolver, позволяющий явно определять сопоставление между URL-адресом и именем метода . См. Следующий пример:
1. Мультиакционный контроллер
Пример мультиакционного контроллера.
package com.mkyong.common.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; public class CustomerController extends MultiActionController{ public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","add() method"); } public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","delete() method"); } public ModelAndView update(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","update() method"); } public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("CustomerPage", "msg","list() method"); } }
2. Свойства-имярешатель
С PropertiesMethodNameResolver , вы можете легко сопоставить любое имя URL-адреса с соответствующим именем метода:
add update delete list add
Теперь URL-адрес будет сопоставлен с именем метода в следующем шаблоне:
- /customer/a.htm –>добавить() метод
- /customer/b.htm –>обновить() метод
- /customer/c.htm –>метод удаления()
- /customer/d.htm –>список() метод
- /customer/whatever.htm –>добавить() метод
Скачать Исходный Код
Ссылка
Оригинал: “https://mkyong.com/spring-mvc/spring-mvc-propertiesmethodnameresolver-example/”