spring 添加controller返回值绑定
@EnableWebMvc
@Configuration
public class Config { @Autowired
private RequestMappingHandlerAdapter handlerAdapter; @PostConstruct
public void init() {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(handlerAdapter.getReturnValueHandlers());
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
handlers.add(0, new ResultResponseHandlerMethodProcessor(messageConverters));
handlerAdapter.setReturnValueHandlers(handlers); handlerAdapter.getCustomReturnValueHandlers().add(0, new ResultResponseHandlerMethodProcessor(messageConverters)); handlerAdapter.afterPropertiesSet();
} }
public class ResultResponseHandlerMethodProcessor extends RequestResponseBodyMethodProcessor {
public ResultResponseHandlerMethodProcessor(List<HttpMessageConverter<?>> messageConverters) {
super(messageConverters);
}
public ResultResponseHandlerMethodProcessor(List<HttpMessageConverter<?>> messageConverters, ContentNegotiationManager contentNegotiationManager) {
super(messageConverters, contentNegotiationManager);
}
@Override
public boolean supportsReturnType(final MethodParameter returnType) {
return returnType.getParameterType() == ResponseResult.class;
}
@Override
public void handleReturnValue(final Object returnValue, final MethodParameter returnType, final ModelAndViewContainer mavContainer, final NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException {
super.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
}
}
spring相关核心类: org.springframework.context.support.AbstractApplicationContext#finishBeanFactoryInitialization org.springframework.beans.factory.support.DefaultListableBeanFactory#preInstantiateSingletons org.springframework.context.support.AbstractApplicationContext#refresh mvcUriComponentsContributor spring bean容器
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor#injectionMetadataCache org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser.CompositeUriComponentsContributorFactoryBean
spring 添加controller返回值绑定的更多相关文章
- Spring MVC controller返回值类型
SpringMVC controller返回值类型: 1 String return "user":将请求转发到user.jsp(forword) return "red ...
- SpringMVC Controller 返回值几种类型
SpringMVC Controller 返回值几种类型 2016年06月21日 19:31:14 为who而生 阅读数:4189 标签: Controller 返回值类型spring mvc 更多 ...
- spring boot 接口返回值封装
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- Asp.net MVC 中Controller返回值类型ActionResult
[Asp.net MVC中Controller返回值类型] 在mvc中所有的controller类都必须使用"Controller"后缀来命名并且对Action也有一定的要求: 必 ...
- spring jdbcTemplate query 返回值为null
spring jdbcTemplate query 返回值为null 今天使用以下方法从数据库中查询数据,返回列表 public List<BookBean> getBooks(){ St ...
- springMVC对于Controller返回值的可选类型
2018-01-11 对于springMVC处理方法支持支持一系列的返回方式: (1)ModelAndView (2)Model (3)ModelMap (4)Map (5)View (6)Stri ...
- SpringMVC Controller 返回值的可选类型
spring mvc 支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void. ModelAndView @RequestMap ...
- springMVC学习(4)-商品修改(RequestMapping解释、controller返回值)
一.需求: 操作流程: 1.进入商品查询列表页面 2.点击修改,进入商品修改页面,页面中显示了要修改的商品(从数据库查询) 3.在商品修改页面,修改商品信息,修改后,点击提交 代码: ItemsMap ...
- 转SpringMVC Controller 返回值的可选类型
spring mvc 支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void. ModelAndView @RequestMap ...
随机推荐
- maven项目org.springframework.web.context.ContextLoaderListener的异常和tomcat zipexception的异常
使用到spring的maven web项目,在运行servers时,报错找不到org.springframework.web.context.ContextLoaderListener,web.xml ...
- 使用fprof基本步骤
$erl -name a@localhost -setcookie abc -remsh b@localhost >fprof:trace([start, {file, "/home/ ...
- 【Leetcode】50. Pow(x, n)
Implement pow(x, n). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 O ...
- 成功解决JSP和Servlet的中文乱码问题
表单提交时出现乱码: 在进行表单提交的时候,经常提交一些中文,自然就避免不了出现中文乱码的情况,对于表单来说有两种提交方式:get和post提交方式.所以请求的时候便有get请求和post请求.以前我 ...
- form 表单提交类型
multipart/form-data与x-www-form-urlencoded区别 multipart/form-data:既可以上传文件等二进制数据,也可以上传表单键值对,只是最后会转化为一条信 ...
- Oracle schema 的含义
方案(Schema)为数据库对象的集合,为了区分各个集合,我们需要给这个集合起个名字,这些名字就是我们在企业管理器的方案下看到的许多类似用户名的节点,这些类似用户名的节点其实就是一个schema,sc ...
- 【C++】构造函数不能是虚函数
1 虚函数对应一个vtable,这大家都知道,可是这个vtable其实是存储在对象的内存空间的.问题出来了,如果构造函数是虚的,就需要通过 vtable来调用,可是对象还没有实例化,也就是内存空间还没 ...
- Linux下启用MySQL慢查询
MySQL在linux系统中的配置文件一般是my.cnf找到[mysqld]下面加上log-slow-queries=/data/mysqldata/slowquery.loglong_query_t ...
- HttpWebRequest 保存Cookies,模拟Session登录
前面使用HttpWebRequest 对象可以抓取网页中一些资料,不过有些页面可以直接打开,而有些页面必登录之后才能打开,也就是在登录后保存登录信息在Session,这样就可以访问有权限的页面了.下面 ...
- BZOJ 1566 管道取珠(DP)
求方案数的平方之和.这个看起来很难解决.如果转化为求方案数的有序对的个数.那么就相当于求A和B同时取,最后序列一样的种数. 令dp[i][j][k]表示A在上管道取了i个,下管道取了j个,B在上管道取 ...