控制器中现有请求映射的新 implementation/method
New implementation/method of existing request mapping in controller
我正在尝试寻找一种方法来扩展控制器,以便我可以使用现有的请求映射,但绑定了不同的 implementation/method。
例如,下面是 BLC 中 AdminBasicEntityController 的代码片段,其中 viewAddEntityForm 方法绑定到 /添加 请求映射。现在我想要使用 /add 请求映射来显示 entityForm(Say Product entity) 的逻辑。可能吗?
@Controller("blAdminBasicEntityController")
@RequestMapping("/{sectionKey:.+}")
public class AdminBasicEntityController extends AdminAbstractController {
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@RequestParam MultiValueMap<String, String> requestParams) throws Exception {
// default implementation
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String viewAddEntityForm(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@RequestParam(defaultValue = "") String entityType) throws Exception {
// default implementation
}
}
我还在 AdminBasicEntityController 的文档中找到了下面提到的信息,这是否意味着我可以拥有特定实体的控制器。如果是,如何?
The default implementation of the {@link #BroadleafAdminAbstractEntityController}. This delegates every call to super and does not provide any custom-tailored functionality. It is
responsible for rendering the admin for every entity that is not
explicitly customized by its own controller
@RequestMapping("/{sectionKey:.+}")
使用通用路径变量 sectionKey
,使控制器处理任何未显式映射的请求。例如,
/product
/product/add
/category
/category/add
/store
/store/add
如果这些 URL 未明确映射到它们自己的控制器,则可能都在使用此控制器。
要自己处理特定的 URL,您可以这样做:
@Controller
@RequestMapping("/product")
public class ProductAdminController {
@RequestMapping("/add")
public String viewAddEntityForm(...) { ... }
}
现在,URL /product/add
将路由到此自定义控制器,而所有其他控制器将继续路由到通用控制器。
我正在尝试寻找一种方法来扩展控制器,以便我可以使用现有的请求映射,但绑定了不同的 implementation/method。
例如,下面是 BLC 中 AdminBasicEntityController 的代码片段,其中 viewAddEntityForm 方法绑定到 /添加 请求映射。现在我想要使用 /add 请求映射来显示 entityForm(Say Product entity) 的逻辑。可能吗?
@Controller("blAdminBasicEntityController")
@RequestMapping("/{sectionKey:.+}")
public class AdminBasicEntityController extends AdminAbstractController {
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@RequestParam MultiValueMap<String, String> requestParams) throws Exception {
// default implementation
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String viewAddEntityForm(HttpServletRequest request, HttpServletResponse response, Model model,
@PathVariable Map<String, String> pathVars,
@RequestParam(defaultValue = "") String entityType) throws Exception {
// default implementation
}
}
我还在 AdminBasicEntityController 的文档中找到了下面提到的信息,这是否意味着我可以拥有特定实体的控制器。如果是,如何?
The default implementation of the {@link #BroadleafAdminAbstractEntityController}. This delegates every call to super and does not provide any custom-tailored functionality. It is responsible for rendering the admin for every entity that is not explicitly customized by its own controller
@RequestMapping("/{sectionKey:.+}")
使用通用路径变量 sectionKey
,使控制器处理任何未显式映射的请求。例如,
/product
/product/add
/category
/category/add
/store
/store/add
如果这些 URL 未明确映射到它们自己的控制器,则可能都在使用此控制器。
要自己处理特定的 URL,您可以这样做:
@Controller
@RequestMapping("/product")
public class ProductAdminController {
@RequestMapping("/add")
public String viewAddEntityForm(...) { ... }
}
现在,URL /product/add
将路由到此自定义控制器,而所有其他控制器将继续路由到通用控制器。