好吧,我有一个可能的解决方案。它以前对我不起作用,因为我忘记了 register jaxrs:provider
控制器:
@GET
@Path("/benchmark")
@Produces("text/html")
public MyModel getForbiddenBrowserList() {
MyModel model = generateMyModel();
//And now I want to do something like:
return MyModel;
}
jax-rs 弹簧配置:
<jaxrs:server id="notesService" address="/">
...
<jaxrs:providers>
<ref bean="dispatchProvider"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="dispatchProvider" class="org.apache.cxf.jaxrs.provider.RequestDispatcherProvider">
<property name="classResources">
<map>
<entry key="com.acme.MyModel" value="/WEB-INF/pages/model.jsp"/>
</map>
</property>
<property name="beanNames">
<map>
<entry key="com.acme.MyModel" value="myModel"/>
</map>
</property>
</bean>
和model.jsp:
<%@ page import="com.acme.MyModel" %>
<%
MyModel myModel= (MyModel) request.getAttribute("myModel");
%>
<html>
<head></head>
<body>
Model: <%= myModel.value %>
</body>
</html>