SpringMVC使用自定义视图解析器

xiaoxiao2021-02-28  96

1.创建一个类实现View接口,实现接口中的两个方法

@Component

public MyView implements View{

@Override

public String getContentType(){

return null;

}

@Override

public void render(Map<String,?> model,HttpServletRequest request,HttpServletResponse response){

reponse.getWriter().print("MyView");

}

}

2.在SpringMVC的配置文件中配置视图解析器

<bean class="org.springframework.web.servlert.view.BeanNameViewResolver">

<!--配置视图解析器的优先级-->

<property name="order" value="10"/>

</bean>

优先级值越大,优先级越小。当配置有多个视图解析器时,先使用优先级大的视图解析器。如果优先级大的解析器解析不了,则使用优先级次大的。不要忘记在类名前加注释

@Component

转载请注明原文地址: https://www.6miu.com/read-96492.html

最新回复(0)