本文整理了Java中org.springframework.web.servlet.ModelAndView
类的一些代码示例,展示了ModelAndView
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelAndView
类的具体详情如下:
包路径:org.springframework.web.servlet.ModelAndView
类名称:ModelAndView
[英]Holder for both Model and View in the web MVC framework. Note that these are entirely distinct. This class merely holds both to make it possible for a controller to return both model and view in a single return value.
Represents a model and view returned by a handler, to be resolved by a DispatcherServlet. The view can take the form of a String view name which will need to be resolved by a ViewResolver object; alternatively a View object can be specified directly. The model is a Map, allowing the use of multiple objects keyed by name.
[中]web MVC框架中模型和视图的持有者。请注意,这些是完全不同的。这个类只保存这两个属性,以便控制器可以在一个返回值中同时返回模型和视图。
表示处理程序返回的模型和视图,由DispatcherServlet解析。视图可以采用字符串视图名称的形式,该名称需要由ViewResolver对象解析;或者,可以直接指定视图对象。该模型是一个地图,允许使用按名称键入的多个对象。
代码示例来源:origin: gocd/gocd
@RequestMapping(value = "/tab/pipeline/history", method = RequestMethod.GET)
public ModelAndView list(@RequestParam("pipelineName") String pipelineName) {
Map model = new HashMap();
try {
PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
model.put("pipelineName", pipelineConfig.name());
model.put("isEditableViaUI", goConfigService.isPipelineEditable(pipelineName));
return new ModelAndView("pipeline/pipeline_history", model);
} catch (PipelineNotFoundException e) {
model.put("errorMessage", e.getMessage());
return new ModelAndView("exceptions_page", model);
}
}
代码示例来源:origin: Raysmond/SpringBlog
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
public ModelAndView notFound(HttpServletRequest request, NotFoundException exception) {
String uri = request.getRequestURI();
log.error("Request page: {} raised NotFoundException {}", uri, exception);
ModelAndView model = new ModelAndView("error/general");
model.addObject("status", HttpStatus.NOT_FOUND.value());
model.addObject("error", HttpStatus.NOT_FOUND.getReasonPhrase());
model.addObject("path", uri);
model.addObject("customMessage", exception.getMessage());
return model;
}
代码示例来源:origin: spring-projects/spring-framework
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, getStatusCode());
ModelAndView modelAndView = new ModelAndView();
modelAndView.addAllObjects(RequestContextUtils.getInputFlashMap(request));
if (viewName != null) {
modelAndView.setViewName(viewName);
modelAndView.setView(getView());
代码示例来源:origin: spring-projects/spring-framework
/**
* Return a ModelAndView for the given view name and exception.
* <p>The default implementation adds the specified exception attribute.
* Can be overridden in subclasses.
* @param viewName the name of the error view
* @param ex the exception that got thrown during handler execution
* @return the ModelAndView instance
* @see #setExceptionAttribute
*/
protected ModelAndView getModelAndView(String viewName, Exception ex) {
ModelAndView mv = new ModelAndView(viewName);
if (this.exceptionAttribute != null) {
mv.addObject(this.exceptionAttribute, ex);
}
return mv;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Do we need view name translation?
*/
private void applyDefaultViewName(HttpServletRequest request, @Nullable ModelAndView mv) throws Exception {
if (mv != null && !mv.hasView()) {
String defaultViewName = getDefaultViewName(request);
if (defaultViewName != null) {
mv.setViewName(defaultViewName);
}
}
}
代码示例来源:origin: stackoverflow.com
@ControllerAdvice
public class ExceptionHandlerController {
public static final String DEFAULT_ERROR_VIEW = "error";
@ExceptionHandler(value = {Exception.class, RuntimeException.class})
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) {
ModelAndView mav = new ModelAndView(DEFAULT_ERROR_VIEW);
mav.addObject("datetime", new Date());
mav.addObject("exception", e);
mav.addObject("url", request.getRequestURL());
return mav;
}
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value = "/licensing/organisation/edit/{organisationId}/employee/news/add/{employeeId}", method = RequestMethod.GET)
public ModelAndView addOrganisationNewsForm(@PathVariable Long organisationId,@PathVariable Long employeeId, @RequestParam("redirect") String redirect, @ModelAttribute("news") News news, BindingResult bindingResult) {
ModelAndView results = new ModelAndView("container.platform.licensing.news.add");
results.addObject("organisationId", organisationId);
results.addObject("employeeId", employeeId);
results.addObject("redirect", redirect);
return results;
}
@RequestMapping(value = "/licensing/organisation_group/news/add/{organisationGroupId}", method = RequestMethod.GET)
代码示例来源:origin: ucarGroup/DataLink
@RequestMapping(value = "/toTaskException")
public ModelAndView toTaskException(HttpServletRequest request) {
Long taskId = Long.valueOf(request.getParameter("taskId"));
ModelAndView mav = new ModelAndView("taskMonitor/taskException");
mav.addObject("taskId", taskId);
return mav;
}
代码示例来源:origin: psi-probe/psi-probe
@Override
protected ModelAndView handleContext(String contextName, Context context,
HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpSession session = request.getSession(false);
Summary summary = (Summary) session.getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE);
if (summary != null && "post".equalsIgnoreCase(request.getMethod())) {
List<String> names = new ArrayList<>();
for (String name : Collections.list(request.getParameterNames())) {
if ("on".equals(request.getParameter(name))) {
names.add(name);
}
}
getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names);
request.getSession(false).setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary);
} else if (summary != null && contextName.equals(summary.getName())) {
String name = ServletRequestUtils.getStringParameter(request, "source", null);
if (name != null) {
List<String> names = new ArrayList<>();
names.add(name);
getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names);
request.getSession(false).setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary);
} else {
logger.error("source is not passed, nothing to do");
}
}
return new ModelAndView(new RedirectView(request.getContextPath()
+ ServletRequestUtils.getStringParameter(request, "view", getViewName()) + "?"
+ request.getQueryString()));
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value = "/licensing/organisation_group/news/add/{organisationGroupId}", method = RequestMethod.POST)
public ModelAndView addOrganisationGroupProcessForm(@PathVariable Long organisationGroupId, @RequestParam("redirect") String redirect, @Valid @ModelAttribute("news") News news, BindingResult bindingResult) {
ModelAndView results = new ModelAndView();
if(!bindingResult.hasErrors()) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
OrganisationGroup group=licensingControllerHelper.getOrganisationGroupById(organisationGroupId);
news = licensingService.addOrganisationGroupNews(news, group, username);
results.setViewName("redirect:/licensing/organisation_group/view/"+organisationGroupId);
} else {
results.setViewName("container.platform.licensing.news.add");
results.addObject("organisationGroupId", organisationGroupId);
results.addObject("redirect", redirect);
}
return results;
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value = "/licensing/organisation/edit/{organisationId}/organisationIp/edit/{organisationIpId}", method = RequestMethod.POST)
public ModelAndView editOrganisationIpProcessForm(@PathVariable Long organisationId, @PathVariable Long organisationIpId,
@ModelAttribute("organisationIpDescriptor") OrganisationIp organisationIp, BindingResult bindingResult) {
ModelAndView results = new ModelAndView();
if (!bindingResult.hasErrors()) {
results.setViewName("redirect:/licensing/organisation/view/" + organisationId);
String username = SecurityContextHolder.getContext().getAuthentication().getName();
licensingService.addIpComment(organisationIp, username);
} else {
results.setViewName("container.platform.licensing.organisationIp.edit");
}
return results;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@RequestMapping("/method")
public ModelAndView method(MyEntity object) {
return new ModelAndView("/something");
}
}
代码示例来源:origin: psi-probe/psi-probe
@Override
protected ModelAndView handleContext(String contextName, Context context,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String attrName = ServletRequestUtils.getStringParameter(request, "attr");
context.getServletContext().removeAttribute(attrName);
return new ModelAndView(new RedirectView(
request.getContextPath() + getViewName() + "?" + request.getQueryString()));
}
代码示例来源:origin: cloudfoundry/uaa
@RequestMapping(value = "/oauth/authorize")
public ModelAndView authorize(Map<String, Object> model,
@RequestParam Map<String, String> parameters,
SessionStatus sessionStatus,
Principal principal,
return new ModelAndView(new RedirectView(addQueryParameter(addQueryParameter(resolvedRedirect, "error","invalid_request"), "error_description", "Missing response_type in authorization request")));
return new ModelAndView(getAuthorizationCodeResponse(authorizationRequest,
(Authentication) principal));
return new ModelAndView(
new RedirectView(addFragmentComponent(resolvedRedirect, "error=interaction_required"))
);
} else {
logger.debug("Unable to handle /oauth/authorize, internal error", e);
if ("none".equals(authorizationRequest.getRequestParameters().get("prompt"))) {
return new ModelAndView(
new RedirectView(addFragmentComponent(resolvedRedirect, "error=internal_server_error"))
);
代码示例来源:origin: spring-projects/spring-security-oauth
@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) throws Exception {
final String approvalContent = createTemplate(model, request);
if (request.getAttribute("_csrf") != null) {
model.put("_csrf", request.getAttribute("_csrf"));
}
View approvalView = new View() {
@Override
public String getContentType() {
return "text/html";
}
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType(getContentType());
response.getWriter().append(approvalContent);
}
};
return new ModelAndView(approvalView, model);
}
代码示例来源:origin: psi-probe/psi-probe
@Override
protected ModelAndView handleContext(String contextName, Context context,
HttpServletRequest request, HttpServletResponse response) throws Exception {
boolean compile = ServletRequestUtils.getBooleanParameter(request, "compile", false);
HttpSession session = request.getSession(false);
Summary summary = (Summary) session.getAttribute(SUMMARY_ATTRIBUTE);
if (summary == null || !contextName.equals(summary.getName())) {
summary = new Summary();
summary.setName(contextName);
}
getContainerWrapper().getTomcatContainer().listContextJsps(context, summary, compile);
request.getSession(false).setAttribute(SUMMARY_ATTRIBUTE, summary);
if (compile) {
return new ModelAndView(new RedirectView(
request.getRequestURI() + "?webapp=" + (contextName.length() == 0 ? "/" : contextName)));
}
return new ModelAndView(getViewName(), "summary", summary);
}
代码示例来源:origin: pl.edu.icm.synat/synat-console-core
@RequestMapping(value = "/licensing/organisation/edit/{organisationId}/organisationIp/remove/{organisationIpId}", method = RequestMethod.POST)
public ModelAndView removeOrganisationIpProcessForm(@PathVariable Long organisationId, @PathVariable Long organisationIpId,
@RequestParam(defaultValue = "") String comment) {
ModelAndView results = new ModelAndView();
results.setViewName("redirect:/licensing/organisation/view/" + organisationId);
Organisation organisation = licensingControllerHelper.getOrganisationById(organisationId);
OrganisationIp organisationIp = licensingControllerHelper.getOrganisationIpById(organisation, organisationIpId);
String username = SecurityContextHolder.getContext().getAuthentication().getName();
organisation = licensingService.removeOrganisationIp(organisationIp, comment, username);
return results;
}
代码示例来源: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;
});
}
代码示例来源:origin: org.onap.portal.sdk/epsdk-analytics
@RequestMapping(value = { "/report_embedded" }, method = RequestMethod.GET)
public ModelAndView reportEmbedded(HttpServletRequest request) {
request.getSession().setAttribute("isEmbedded", true);
return new ModelAndView("report_embedded");
}
代码示例来源:origin: bill1012/AdminEAP
@RequestMapping(value = "/redis/connect",method = RequestMethod.GET)
private ModelAndView redisConnectFailure(ModelAndView modelAndView, HttpServletRequest request){
String basePath = request.getContextPath();
request.setAttribute("basePath", basePath);
modelAndView.addObject("errorName","redisConnectionFailure");
modelAndView.addObject("message","连接redis错误,请确认redis配置正确,且设置了正确的密码");
modelAndView.addObject("detail", ErrorConstant.ERROR_DETAIL);
modelAndView.setViewName("base/error/error");
return modelAndView;
}
内容来源于网络,如有侵权,请联系作者删除!