假设我想创建一个控制器类“MyController”,在其中我想使用spring @RequestMapping注释来注释各种方法:
-@RequestMapping("/employee-management/employees")
public String getAllEmployees(Model model)
-@RequestMapping("/employee-management/employee/{someID}")
public String getEmployee(@PathVariable(value="someID") String id)
我想在这样的主java方法中调用此控制器:
public static void main(String [] args) {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest1.getRequestURI()).thenReturn("/employee-management/employee/122");
DispatcherServlet MyDispatcherServlet= new DispatcherServlet();
// [here i want to init MyDispatcherServlet with the httpServletRequest object] and i want it to call the appropriate method mapped within "MyController" class]
我希望所有这些都在容器之外运行(例如tomcat)。