Skip to main content
 首页 » 编程设计

jakarta-ee中spring mvc Controller 等效于 javaee Controller

2025年01月19日6insus

我使用了 Spring 。

纯纯 java-ee 6/7 是否有等效的 Controller 策略? 就像有 Spring Controller 负责处理路径参数、请求参数、返回类型、重定向、重定向到带有 modelAndView 对象的 View 来携带数据?

@Controller 
class MyControllerClass { 
 
      @RequestMapping... 
      method(){ 
         ServiceCall()... 
      //put something to modelAndView object here and redirect to jsp page. 
      return "home"; // this will redirect data to home.jsp 
 
      } 
} 

请您参考如下方法:

一个想法是使用 JAX-RS 的 Jersey 实现.

Controller 看起来像:

@Path("same_as_the_class_request_mapping") 
public class MyControllerClass{ 
 
    @Path("pretty_much_same_as_the_method_request_mapping") 
    @GET //or whatever you need 
    public Viewable roaster(){ 
        //do whatever 
        return new Viewable("home", some_model_object); 
    } 
} 

您可以查看更多信息here和一个很好的教程here .

Jersey 还使您能够与 Spring 集成,从而使人们能够从 Jersey Controller 调用 Spring 服务。查看this了解更多详情