本文整理匯總了Java中org.springframework.web.servlet.view.json.MappingJackson2JsonView.setObjectMapper方法的典型用法代碼示例。如果您正苦於以下問題:Java MappingJackson2JsonView.setObjectMapper方法的具體用法?Java MappingJackson2JsonView.setObjectMapper怎麽用?Java MappingJackson2JsonView.setObjectMapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.servlet.view.json.MappingJackson2JsonView
的用法示例。
在下文中一共展示了MappingJackson2JsonView.setObjectMapper方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveException
import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception e) {
// log記錄異常
LOGGER.error(e.getMessage(), e);
// 非控製器請求照成的異常
if (!(handler instanceof HandlerMethod)) {
return new ModelAndView("error/500");
}
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (WebUtils.isAjax(handlerMethod)) {
Result result = new Result();
result.setMsg(e.getMessage());
MappingJackson2JsonView view = new MappingJackson2JsonView();
view.setObjectMapper(jacksonObjectMapper);
view.setContentType("text/html;charset=UTF-8");
return new ModelAndView(view, BeanUtils.toMap(result));
}
// 頁麵指定狀態為500,便於上層的resion或者nginx的500頁麵跳轉,由於error/500不適合對用戶展示
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return new ModelAndView("error/500").addObject("error", e.getMessage());
}
示例2: generateModelAndViewForErrorResponse
import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
/**
* Reusable static method for generating a ModelAndView that will be serialized to a JSON representation of the
* DefaultErrorContractDTO.
*
* @return A ModelAndView that will be serialized to a JSON representation of the DefaultErrorContractDTO. (NOTE:
* make sure the DefaultErrorContractDTO is FULLY populated before calling this method! Changes to the
* DefaultErrorContractDTO after calling this method may not be reflected in the returned ModelAndView).
*/
public ModelAndView generateModelAndViewForErrorResponse(
DefaultErrorContractDTO errorContractDTO, int httpStatusCode, Collection<ApiError> rawFilteredApiErrors,
Throwable originalException, RequestInfoForLogging request
) {
MappingJackson2JsonView view = new MappingJackson2JsonView();
view.setExtractValueFromSingleKeyModel(true);
view.setObjectMapper(getObjectMapperForJsonErrorResponseSerialization(
errorContractDTO, httpStatusCode, rawFilteredApiErrors, originalException, request
));
ModelAndView mv = new ModelAndView(view);
mv.addObject(errorContractDTO);
return mv;
}
示例3: configureViewResolvers
import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
MappingJackson2JsonView mappingJackson2JsonView = new MappingJackson2JsonView();
mappingJackson2JsonView.setObjectMapper(objectMapper);
registry.enableContentNegotiation(true, mappingJackson2JsonView);
registry.viewResolver(viewResolver);
}
示例4: defaultView
import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入方法依賴的package包/類
@Bean
public View defaultView() {
MappingJackson2JsonView bean = new MappingJackson2JsonView();
bean.setObjectMapper(jsonObjectMapper());
return bean;
}