• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ModelAndViewResolver类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver的典型用法代码示例。如果您正苦于以下问题:Java ModelAndViewResolver类的具体用法?Java ModelAndViewResolver怎么用?Java ModelAndViewResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ModelAndViewResolver类属于org.springframework.web.servlet.mvc.annotation包,在下文中一共展示了ModelAndViewResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doResolveException

点赞 3

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
                                          Object _handler, Exception ex) {
    HandlerMethod handler = (HandlerMethod) _handler;
    if (handler == null) {
        return null;
    }
    Method method = handler.getMethod();
    if (method.isAnnotationPresent(JsonBody.class) && ex != null) {
        logger.error("server is error", ex);
        Object value = null;
        if (ex instanceof ServiceException) {
            value = new JsonResult<Object>(((ServiceException) ex).getCode(), ex.getMessage());
        } else {
            value = new JsonResult<Object>(-1, ex.getMessage());
        }
        try {
            JsonUtil.writeValue(response.getWriter(), value);
        } catch (IOException e) {
            Throwables.propagateIfPossible(e);
        }
        return ModelAndViewResolver.UNRESOLVED;
    }
    return null;
}
 

开发者ID:didapinchegit,
项目名称:rocket-console,
代码行数:26,
代码来源:JsonBodyExceptionResolver.java

示例2: mavResolver

点赞 3

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
@Test
public void mavResolver() throws ServletException, IOException {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			ModelAndViewResolver[] mavResolvers = new ModelAndViewResolver[] {new MyModelAndViewResolver()};
			adapterDef.getPropertyValues().add("modelAndViewResolvers", mavResolvers);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, ModelAndViewResolverController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("myValue", response.getContentAsString());

}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:19,
代码来源:ServletAnnotationControllerHandlerMethodTests.java

示例3: doResolveException

点赞 3

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
@Override
    protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
                                              Object _handler, Exception ex) {
        LOGGER.info("jsonBody exception....");
        HandlerMethod handler = (HandlerMethod) _handler;
        if (handler == null) {
            // like 'GET' not supported
            return null;
        }

        Method method = handler.getMethod();

        if (method.isAnnotationPresent(JsonBody.class)) {
//            String config = super.determineViewName(ex, request);
//            Object value = Strings.isNullOrEmpty(config) ? ex : JsonSerializer.parseConfig(config, ex);
            JsonSerializer.write(ex, method, request, response);
            // skip other resolver and view render
            return ModelAndViewResolver.UNRESOLVED;
        }

        return null;
    }
 

开发者ID:glameyzhou,
项目名称:scaffold,
代码行数:23,
代码来源:JsonBodyExceptionResolver.java

示例4: handleReturnValue

点赞 2

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (this.mavResolvers != null) {
		for (ModelAndViewResolver mavResolver : this.mavResolvers) {
			Class<?> handlerType = returnType.getContainingClass();
			Method method = returnType.getMethod();
			ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
			ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
			if (mav != ModelAndViewResolver.UNRESOLVED) {
				mavContainer.addAllAttributes(mav.getModel());
				mavContainer.setViewName(mav.getViewName());
				if (!mav.isReference()) {
					mavContainer.setView(mav.getView());
				}
				return;
			}
		}
	}

	// No suitable ModelAndViewResolver...
	if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
		this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
	}
	else {
		throw new UnsupportedOperationException("Unexpected return type: " +
				returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:31,
代码来源:ModelAndViewResolverMethodReturnValueHandler.java

示例5: setUp

点赞 2

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
@Before
public void setUp() {
	mavResolvers = new ArrayList<ModelAndViewResolver>();
	handler = new ModelAndViewResolverMethodReturnValueHandler(mavResolvers);
	mavContainer = new ModelAndViewContainer();
	request = new ServletWebRequest(new MockHttpServletRequest());
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:8,
代码来源:ModelAndViewResolverMethodReturnValueHandlerTests.java

示例6: resolveModelAndView

点赞 2

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public ModelAndView resolveModelAndView(Method method, Class handlerType, Object returnValue,
		ExtendedModelMap model, NativeWebRequest request) {
	if (returnValue != null && returnValue.getClass().equals(returnValueType)) {
		return new ModelAndView("viewName", "modelAttrName", returnValue);
	}
	else {
		return ModelAndViewResolver.UNRESOLVED;
	}
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:12,
代码来源:ModelAndViewResolverMethodReturnValueHandlerTests.java

示例7: handleReturnValue

点赞 2

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
public void handleReturnValue(
		Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest request)
		throws Exception {

	if (this.mavResolvers != null) {
		for (ModelAndViewResolver mavResolver : this.mavResolvers) {
			Class<?> handlerType = returnType.getDeclaringClass();
			Method method = returnType.getMethod();
			ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
			ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, request);
			if (mav != ModelAndViewResolver.UNRESOLVED) {
				mavContainer.addAllAttributes(mav.getModel());
				mavContainer.setViewName(mav.getViewName());
				if (!mav.isReference()) {
					mavContainer.setView(mav.getView());
				}
				return;
			}
		}
	}

	// No suitable ModelAndViewResolver..

	if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
		this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request);
	}
	else {
		throw new UnsupportedOperationException("Unexpected return type: "
				+ returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}
 

开发者ID:deathspeeder,
项目名称:class-guard,
代码行数:33,
代码来源:ModelAndViewResolverMethodReturnValueHandler.java

示例8: getModelAndViewResolvers

点赞 2

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Return the configured {@link ModelAndViewResolver}s, or {@code null}.
 */
public List<ModelAndViewResolver> getModelAndViewResolvers() {
	return modelAndViewResolvers;
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:7,
代码来源:RequestMappingHandlerAdapter.java

示例9: ModelAndViewResolverMethodReturnValueHandler

点赞 2

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Create a new instance.
 */
public ModelAndViewResolverMethodReturnValueHandler(List<ModelAndViewResolver> mavResolvers) {
	this.mavResolvers = mavResolvers;
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:7,
代码来源:ModelAndViewResolverMethodReturnValueHandler.java

示例10: setCustomModelAndViewResolver

点赞 1

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Set a custom ModelAndViewResolvers to use for special method return types.
 * Such a custom ModelAndViewResolver will kick in first, having a chance to
 * resolve an return value before the standard ModelAndView handling kicks in.
 */
public void setCustomModelAndViewResolver(ModelAndViewResolver customModelAndViewResolver) {
	this.customModelAndViewResolvers = new ModelAndViewResolver[]{customModelAndViewResolver};
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:9,
代码来源:AnnotationMethodHandlerAdapter.java

示例11: setCustomModelAndViewResolvers

点赞 1

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Set one or more custom ModelAndViewResolvers to use for special method return types.
 * Any such custom ModelAndViewResolver will kick in first, having a chance to
 * resolve an return value before the standard ModelAndView handling kicks in.
 */
public void setCustomModelAndViewResolvers(ModelAndViewResolver... customModelAndViewResolvers) {
	this.customModelAndViewResolvers = customModelAndViewResolvers;
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:9,
代码来源:AnnotationMethodHandlerAdapter.java

示例12: setModelAndViewResolvers

点赞 1

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Provide custom {@link ModelAndViewResolver}s.
 * <p><strong>Note:</strong> This method is available for backwards
 * compatibility only. However, it is recommended to re-write a
 * {@code ModelAndViewResolver} as {@link HandlerMethodReturnValueHandler}.
 * An adapter between the two interfaces is not possible since the
 * {@link HandlerMethodReturnValueHandler#supportsReturnType} method
 * cannot be implemented. Hence {@code ModelAndViewResolver}s are limited
 * to always being invoked at the end after all other return value
 * handlers have been given a chance.
 * <p>A {@code HandlerMethodReturnValueHandler} provides better access to
 * the return type and controller method information and can be ordered
 * freely relative to other return value handlers.
 */
public void setModelAndViewResolvers(List<ModelAndViewResolver> modelAndViewResolvers) {
	this.modelAndViewResolvers = modelAndViewResolvers;
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:18,
代码来源:RequestMappingHandlerAdapter.java

示例13: setCustomModelAndViewResolvers

点赞 1

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Set one or more custom ModelAndViewResolvers to use for special method return types.
 * Any such custom ModelAndViewResolver will kick in first, having a chance to
 * resolve an return value before the standard ModelAndView handling kicks in.
 */
public void setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAndViewResolvers) {
	this.customModelAndViewResolvers = customModelAndViewResolvers;
}
 

开发者ID:deathspeeder,
项目名称:class-guard,
代码行数:9,
代码来源:AnnotationMethodHandlerAdapter.java

示例14: setCustomModelAndViewResolver

点赞 1

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Set a custom ModelAndViewResolvers to use for special method return
 * types.
 * <p>
 * Such a custom ModelAndViewResolver will kick in first, having a chance to
 * resolve a return value before the standard ModelAndView handling kicks
 * in.
 */
public void setCustomModelAndViewResolver(
		ModelAndViewResolver customModelAndViewResolver) {
	this.customModelAndViewResolvers = new ModelAndViewResolver[] { customModelAndViewResolver };
}
 

开发者ID:xiyelife,
项目名称:jresplus,
代码行数:13,
代码来源:ExtendableAnnotationMethodHandlerAdapter.java

示例15: setCustomModelAndViewResolvers

点赞 1

import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; //导入依赖的package包/类
/**
 * Set one or more custom ModelAndViewResolvers to use for special method
 * return types.
 * <p>
 * Any such custom ModelAndViewResolver will kick in first, having a chance
 * to resolve a return value before the standard ModelAndView handling kicks
 * in.
 */
public void setCustomModelAndViewResolvers(
		ModelAndViewResolver[] customModelAndViewResolvers) {
	this.customModelAndViewResolvers = customModelAndViewResolvers;
}
 

开发者ID:xiyelife,
项目名称:jresplus,
代码行数:13,
代码来源:ExtendableAnnotationMethodHandlerAdapter.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)