com.github.datalking.web.support.ModelMethodProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-mvc Show documentation
Show all versions of play-mvc Show documentation
simple mvc framework based on java servlet.
The newest version!
package com.github.datalking.web.support;
import com.github.datalking.common.MethodParameter;
import com.github.datalking.web.bind.WebDataBinderFactory;
import com.github.datalking.web.context.request.WebRequest;
import com.github.datalking.web.mvc.Model;
/**
* 解析Model类型参数和返回值的类
*
* @author yaoo on 5/2/18
*/
public class ModelMethodProcessor implements HandlerMethodArgumentResolver, HandlerMethodReturnValueHandler {
public boolean supportsParameter(MethodParameter parameter) {
return Model.class.isAssignableFrom(parameter.getParameterType());
}
public Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
WebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
return mavContainer.getModel();
}
public boolean supportsReturnType(MethodParameter returnType) {
return Model.class.isAssignableFrom(returnType.getParameterType());
}
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
WebRequest webRequest) throws Exception {
if (returnValue == null) {
return;
} else if (returnValue instanceof Model) {
mavContainer.addAllAttributes(((Model) returnValue).asMap());
} else {
// should not happen
throw new UnsupportedOperationException("Unexpected return type: " +
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy