當前位置: 首頁>>代碼示例>>Java>>正文


Java MappingJackson2JsonView類代碼示例

本文整理匯總了Java中org.springframework.web.servlet.view.json.MappingJackson2JsonView的典型用法代碼示例。如果您正苦於以下問題:Java MappingJackson2JsonView類的具體用法?Java MappingJackson2JsonView怎麽用?Java MappingJackson2JsonView使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MappingJackson2JsonView類屬於org.springframework.web.servlet.view.json包,在下文中一共展示了MappingJackson2JsonView類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: contentNegotiatingViewResolver

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@Bean
public ViewResolver contentNegotiatingViewResolver() {
    logger.debug("Configuring the ContentNegotiatingViewResolver");
    ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
    List<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();

    UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
    urlBasedViewResolver.setViewClass(JstlView.class);
    urlBasedViewResolver.setSuffix(".html");
    viewResolvers.add(urlBasedViewResolver);

    viewResolver.setViewResolvers(viewResolvers);

    List<View> defaultViews = new ArrayList<View>();
    defaultViews.add(new MappingJackson2JsonView());
    viewResolver.setDefaultViews(defaultViews);

    return viewResolver;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:20,代碼來源:CloudUnitApplicationContext.java

示例2: 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());
	}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:25,代碼來源:ExceptionResolver.java

示例3: resolveException

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest,
    HttpServletResponse httpServletResponse, Object o, Exception e) {
  HttpDownServer.LOGGER.error("rest error:",e);
  ModelAndView modelAndView = new ModelAndView();
  try {
    ResultInfo resultInfo = new ResultInfo().setStatus(ResultStatus.ERROR.getCode())
        .setMsg(ResultInfo.MSG_ERROR);
    Map<String, Object> attr = JSON.parseObject(JSON.toJSONString(resultInfo), Map.class);
    MappingJackson2JsonView view = new MappingJackson2JsonView();
    view.setAttributesMap(attr);
    modelAndView.setView(view);
  } catch (Exception e1) {
    e1.printStackTrace();
  }
  return modelAndView;
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:18,代碼來源:RestExceptionHandler.java

示例4: resolveException

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
    e.printStackTrace();
    String messageStr = null;
    if (e instanceof BizException) {
        BizException bz = (BizException) e;
        messageStr = bz.getMessage();
    }

    if (messageStr == null || messageStr.trim().length() == 0) {
        messageStr = "係統異常";
    }

    RestResponse restR = new RestResponse();
    restR.setCode(-1);
    restR.setMessage(messageStr);
    if (HttpRequestUtils.isAjax(request)) {
        Map model = BeanMapConvertUtil.convertBean2Map(restR);
        if (logger.isInfoEnabled()) {
            logger.info(">>>>>resolveException ajax model: " + model);
        }
        return new ModelAndView(new MappingJackson2JsonView(), model);
    }

    return new ModelAndView("500", "restR", restR);
}
 
開發者ID:baidao,項目名稱:tinker-manager,代碼行數:27,代碼來源:WebAppConfig.java

示例5: viewResolver

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@Bean
public ViewResolver viewResolver() {
	ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
	
	List<View> defaultViews = new ArrayList<View>();
	defaultViews.add(new MappingJackson2JsonView());
	resolver.setDefaultViews(defaultViews);
	resolver.setOrder(0);
	
	List<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();
	InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
	internalResourceViewResolver.setPrefix("/WEB-INF/view/");
	internalResourceViewResolver.setSuffix(".jsp");
	internalResourceViewResolver.setOrder(1);
	viewResolvers.add(internalResourceViewResolver);
	resolver.setViewResolvers(viewResolvers);
	
	return resolver;
}
 
開發者ID:EnterKey,項目名稱:enterkey-framework,代碼行數:20,代碼來源:Application.java

示例6: contentNegotiatingViewResolver

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@Bean
public ViewResolver contentNegotiatingViewResolver() {
    LOGGER.debug("Configuring the ContentNegotiatingViewResolver");
    ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
    List<ViewResolver> viewResolvers = new ArrayList<>();

    UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
    urlBasedViewResolver.setViewClass(JstlView.class);
    urlBasedViewResolver.setPrefix("/WEB-INF/pages/");
    urlBasedViewResolver.setSuffix(".jsp");
    viewResolvers.add(urlBasedViewResolver);

    viewResolver.setViewResolvers(viewResolvers);

    List<View> defaultViews = new ArrayList<>();
    defaultViews.add(new MappingJackson2JsonView());
    viewResolver.setDefaultViews(defaultViews);

    return viewResolver;
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:21,代碼來源:DispatcherServletConfiguration.java

示例7: resolve

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@Override
public ModelAndView resolve(final J2EContext ctx, final ProfileManager manager, final String url) {
    final Set<String> prompt = authorizationRequestSupport.getOidcPromptFromAuthorizationRequest(url);
    if (prompt.contains(OidcConstants.PROMPT_NONE)) {
        if (manager.get(true) != null) {
            return new ModelAndView(url);
        }
        final Map<String, String> model = new HashMap<>();
        model.put(OAuth20Constants.ERROR, OidcConstants.LOGIN_REQUIRED);
        return new ModelAndView(new MappingJackson2JsonView(), model);
    }
    return new ModelAndView(new RedirectView(url));
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:14,代碼來源:OidcCallbackAuthorizeViewResolver.java

示例8: handle4AsyncRequest

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
protected ModelAndView handle4AsyncRequest(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
	ExceptionMetadata em = ModuleExceptionResolver.resolveException(ex);
	
	Result<Object> result = new Result<Object>();
	result.setSuccess(false);
	result.setCode(em.getCode());
	result.setMessage(em.getMessage());
	MappingJackson2JsonView jsonView = new MappingJackson2JsonView();
	jsonView.setExtractValueFromSingleKeyModel(true);
	ModelAndView mav = new ModelAndView(jsonView);
	mav.addObject(result);
	return mav;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:14,代碼來源:DefaultMvcHandlerExceptionResolver.java

示例9: createDelegatedView

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
private static MappingJackson2JsonView createDelegatedView() {
    final MappingJackson2JsonView view = new MappingJackson2JsonView();
    view.setPrettyPrint(true);
    view.setDisableCaching(true);
    view.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return view;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:8,代碼來源:Cas30JsonResponseView.java

示例10: createDelegatedView

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
private static MappingJackson2JsonView createDelegatedView() {
    final MappingJackson2JsonView view = new MappingJackson2JsonView();
    view.setPrettyPrint(true);
    view.setDisableCaching(true);
    view.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL).findAndRegisterModules();
    return view;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:8,代碼來源:Cas30JsonResponseView.java

示例11: adaptException2MAV

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
private ModelAndView adaptException2MAV(Exception ex) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    mav.addObject("exception",ex.getClass().getSimpleName());
    mav.addObject("message", ex.getMessage());
    return mav;
}
 
開發者ID:graphium-project,項目名稱:graphium,代碼行數:8,代碼來源:GlobalExceptionController.java

示例12: handleRequest

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@GetMapping(path = {"/idcard"})
public ModelAndView handleRequest(HttpServletRequest request) throws Exception {
    try {
        String encodedCertificate = request.getHeader(HEADER_SSL_CLIENT_CERT);
        Assert.hasLength(encodedCertificate, "Unable to find certificate from request");
        request.getSession().setAttribute(Constants.CERTIFICATE_SESSION_ATTRIBUTE, X509Utils.toX509Certificate(encodedCertificate));
        return new ModelAndView(new MappingJackson2JsonView(), Collections.singletonMap("ok", true));
    } catch (Exception e) {
        this.log(e);
        return new ModelAndView(new MappingJackson2JsonView(), Collections.singletonMap("ok", false));
    }
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:13,代碼來源:IDCardController.java

示例13: findAllMajors2

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@RequestMapping(value="/findAllMajors2",method=RequestMethod.GET)
@ResponseBody
public List<Major> findAllMajors2() throws JsonProcessingException
{
	List<Major> majorList=majorService1.findAllMajors();
       /** 
        * ObjectMapper是JSON操作的核心,Jackson的所有JSON操作都是在ObjectMapper中實現。 
        * ObjectMapper有多個JSON序列化的方法,可以把JSON字符串保存File、OutputStream等不同的介質中。 
        * writeValue(File arg0, Object arg1)把arg1轉成json序列,並保存到arg0文件中。 
        * writeValue(OutputStream arg0, Object arg1)把arg1轉成json序列,並保存到arg0輸出流中。 
        * writeValueAsBytes(Object arg0)把arg0轉成json序列,並把結果輸出成字節數組。 
        * writeValueAsString(Object arg0)把arg0轉成json序列,並把結果輸出成字符串。 
        */  
       ObjectMapper jasonObjMapper = new ObjectMapper();  
       String strJason=jasonObjMapper.writeValueAsString(majorList);
	//return strJason;
	
	
       //開始返回
       MappingJackson2JsonView view = new MappingJackson2JsonView();
       Map<String, Object> attributes = new HashMap<String, Object>();
       attributes.put("success", Boolean.TRUE);
       attributes.put("allCoursesList", majorList);
       
       
	ModelAndView modelAndView1=new ModelAndView();
	//set the name of view
	//view.setView("/course/showAllCourses");
	modelAndView1.setViewName("/major/showAllMajors");
	//add the object into model and view
       //view.setAttributesMap(attributes);
       //modelAndView1.setView(view);
	modelAndView1.addObject(majorList);
       return majorList;

	
}
 
開發者ID:KeithLaiKB,項目名稱:SpringMvcMavenDB,代碼行數:38,代碼來源:MajorController.java

示例14: handlerUnauthenticatedException

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
@ExceptionHandler({OptionalNotPresentException.class})
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handlerUnauthenticatedException(Exception ex, NativeWebRequest request) {
    if ((request.getHeader("accept").contains("application/json"))) {
        MappingJackson2JsonView view = new MappingJackson2JsonView();
        Map<String, Serializable> attributes = new HashMap<>();
        attributes.put("error", HttpStatus.NOT_FOUND);
        view.setAttributesMap(attributes);
        return new ModelAndView(view);
    } else {
        return new ModelAndView("/404");
    }
}
 
開發者ID:izhangzhihao,項目名稱:SSMSeedProject,代碼行數:14,代碼來源:ExceptionHandlerController.java

示例15: handlerExceptionMethod

import org.springframework.web.servlet.view.json.MappingJackson2JsonView; //導入依賴的package包/類
/**
 * 全局Controller異常處理
 *
 * @param ex 異常
 * @return 跳轉出錯頁麵
 */
@ExceptionHandler({Exception.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handlerExceptionMethod(Exception ex, NativeWebRequest request) {
    if ((request.getHeader("accept").contains("application/json"))) {//如果不是異步請求
        MappingJackson2JsonView view = new MappingJackson2JsonView();
        Map<String, java.io.Serializable> attributes = new HashMap<>();
        attributes.put("error", HttpStatus.INTERNAL_SERVER_ERROR);
        if (env.getDefaultProfiles()[0].equals("development")) {
            attributes.put("MSG", ex.toString());
            attributes.put("Line", ex.getStackTrace()[0].getLineNumber());
            attributes.put("Method", ex.getStackTrace()[0].getMethodName());
        }
        view.setAttributesMap(attributes);
        return new ModelAndView(view);
    } else {
        if (env.getDefaultProfiles()[0].equals("development")) {
            ModelAndView modelAndView = new ModelAndView("500");
            modelAndView.addObject("MSG", ex.toString());
            modelAndView.addObject("Line", ex.getStackTrace()[0].getLineNumber());
            modelAndView.addObject("Method", ex.getStackTrace()[0].getMethodName());
            Writer writer = new StringWriter();
            //異常輸出到瀏覽器console
            ex.printStackTrace(new PrintWriter(writer));
            modelAndView.addObject("detailed", writer.toString());
            return modelAndView;
        } else {
            return new ModelAndView("/500");
        }
    }
}
 
開發者ID:izhangzhihao,項目名稱:SSMSeedProject,代碼行數:37,代碼來源:ExceptionHandlerController.java


注:本文中的org.springframework.web.servlet.view.json.MappingJackson2JsonView類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。