org.springframework.web.servlet.ModelAndView.setView()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中org.springframework.web.servlet.ModelAndView.setView()方法的一些代码示例,展示了ModelAndView.setView()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelAndView.setView()方法的具体详情如下:
包路径:org.springframework.web.servlet.ModelAndView
类名称:ModelAndView
方法名:setView

ModelAndView.setView介绍

[英]Set a View object for this ModelAndView. Will override any pre-existing view name or View.
[中]为此ModelAndView设置视图对象。将覆盖任何预先存在的视图名称或视图。

代码示例

代码示例来源:origin: spring-projects/spring-framework

modelAndView.setView(getView());

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private ModelAndView getModelAndView(ModelAndViewContainer mavContainer,
    ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {
  modelFactory.updateModel(webRequest, mavContainer);
  if (mavContainer.isRequestHandled()) {
    return null;
  }
  ModelMap model = mavContainer.getModel();
  ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model, mavContainer.getStatus());
  if (!mavContainer.isViewReference()) {
    mav.setView((View) mavContainer.getView());
  }
  if (model instanceof RedirectAttributes) {
    Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    if (request != null) {
      RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
    }
  }
  return mav;
}

代码示例来源:origin: spring-projects/spring-framework

mav.setViewName(mavContainer.getViewName());
if (!mavContainer.isViewReference()) {
  mav.setView((View) mavContainer.getView());

代码示例来源:origin: org.springframework/spring-webmvc

@Nullable
private ModelAndView getModelAndView(ModelAndViewContainer mavContainer,
    ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception {
  modelFactory.updateModel(webRequest, mavContainer);
  if (mavContainer.isRequestHandled()) {
    return null;
  }
  ModelMap model = mavContainer.getModel();
  ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model, mavContainer.getStatus());
  if (!mavContainer.isViewReference()) {
    mav.setView((View) mavContainer.getView());
  }
  if (model instanceof RedirectAttributes) {
    Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    if (request != null) {
      RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
    }
  }
  return mav;
}

代码示例来源:origin: org.springframework/spring-webmvc

modelAndView.setView(getView());

代码示例来源:origin: stackoverflow.com

@RequestMapping(params = "actionMethod="+Constants.ACTION_METHOD_REPORT)
public ModelAndView generateCSV( 
    @ModelAttribute(Constants.REPORT_FORMBEAN_MODEL_ATTRIBUTE) FormBean formBean,
    ModelAndView mav,
    HttpServletRequest request, 
    HttpServletResponse response) {
  mav.setView(new MyExcelView( /* modify your constructor to pass in your data so the view can build the output */ ));

  return mav;
}

代码示例来源:origin: org.springframework/spring-webmvc

mav.setViewName(mavContainer.getViewName());
if (!mavContainer.isViewReference()) {
  mav.setView((View) mavContainer.getView());

代码示例来源:origin: io.leopard/leopard-captcha

public CaptchaView(int width, int height, Class<? extends CaptchaEngine> engineClazz) {
  super.setView(view);
  this.width = width;
  this.height = height;
  this.engineClazz = engineClazz;
}

代码示例来源:origin: spring-projects/spring-integration

modelAndView.setView((View) view);

代码示例来源:origin: io.leopard/leopard-xparam

public AbstractView() {
  super.setView(view);
}

代码示例来源:origin: stackoverflow.com

@RequestMapping("/myHandler")
public ModelAndView myHandler(@ModelAttribute("myBean") MyBean myBean, BindingResults results, ModelAndView mav) {
 if (results.hasErrors()) {
  mav.setViewName("myErrorView");  // Uses the default view you have setup, passing the name as if you returned a String
 } else {
  mav.setView(new FileOutputView(dataToOutputOrWhatever);  // Custom View class to output file as needed
 }
 return mav
}

代码示例来源:origin: io.leopard/web4j-view

public AbstractView() {
  super.setView(view);
}

代码示例来源:origin: stackoverflow.com

@ControllerAdvice
public class GlobalExceptionHandler {

  @ExceptionHandler(MaxUploadSizeExceededException.class)
  public ModelAndView handleMaxUploadException(MaxUploadSizeExceededException e, HttpServletRequest request, HttpServletResponse response){
    ModelAndView mav = new ModelAndView();
    boolean isJson = request.getRequestURL().toString().contains(".json");
    if (isJson) {
      mav.setView(new MappingJacksonJsonView());
      mav.addObject("result", "nok");
    }
    else mav.setViewName("uploadError");
    return mav;
  }
}

代码示例来源:origin: io.leopard/web4j-view

public FileCacheView(String viewName) {
  super.setView(this.createView(viewName));
}

代码示例来源:origin: stackoverflow.com

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
  Object handler, Exception ex) {
 ModelAndView view = new ModelAndView();
 view.setView(new MappingJacksonJsonView());
 APIResponseData apiResponseData = new APIResponseData();
 if (ex instanceof MaxUploadSizeExceededException) {
  apiResponseData.markFail("error message");
  view.addObject(apiResponseData);
  return view;
 }
 return null;
}

代码示例来源:origin: io.leopard/leopard-xparam

public FileCacheView(String viewName) {
  super.setView(this.createView(viewName));
}

代码示例来源:origin: kaif-open/kaif

@RequestMapping("/hot.rss")
public Object rssFeed() {
 ModelAndView modelAndView = new ModelAndView().addObject("articles",
   articleService.listRssTopArticlesWithCache());
 modelAndView.setView(new HotArticleRssContentView());
 return modelAndView;
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-core-authentication

@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response,
            final Object handler, final ModelAndView modelAndView) {
  if (!StringUtils.isEmpty(request.getQueryString()) && request.getQueryString().contains(CasProtocolConstants.PARAMETER_TICKET)) {
    val view = new RedirectView(request.getRequestURL().toString());
    view.setExposeModelAttributes(false);
    view.setExposePathVariables(false);
    modelAndView.setView(view);
  }
}

代码示例来源:origin: org.apereo.cas/cas-server-support-pac4j-core

@Override
  public void postHandle(final HttpServletRequest request, final HttpServletResponse response,
              final Object handler, final ModelAndView modelAndView) {
    if (modelAndView != null
      && StringUtils.isNotBlank(request.getQueryString())
      && request.getQueryString().contains(CasProtocolConstants.PARAMETER_TICKET)) {
      val v = new RedirectView(request.getRequestURL().toString());
      v.setExposeModelAttributes(false);
      v.setExposePathVariables(false);
      modelAndView.setView(v);
    }
  }
}

代码示例来源:origin: kaif-open/kaif

@RequestMapping("/{zone}/hot.rss")
public Object rssFeed(@PathVariable("zone") String rawZone, HttpServletRequest request) {
 return resolveZone(request, rawZone, zoneInfo -> {
  request.getRequestURL();
  ModelAndView modelAndView = new ModelAndView().addObject("zoneInfo", zoneInfo)
    .addObject("articles",
      articleService.listRssHotZoneArticlesWithCache(zoneInfo.getZone()));
  modelAndView.setView(new HotArticleRssContentView());
  return modelAndView;
 });
}

相关文章