当前位置: 首页>>代码示例>>Java>>正文


Java View类代码示例

本文整理汇总了Java中org.springframework.web.servlet.View的典型用法代码示例。如果您正苦于以下问题:Java View类的具体用法?Java View怎么用?Java View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


View类属于org.springframework.web.servlet包,在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderView

import org.springframework.web.servlet.View; //导入依赖的package包/类
private Map<?, ?> renderView() throws Exception {
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));

    final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
    final View viewDelegated = new View() {
        @Override
        public String getContentType() {
            return MediaType.TEXT_HTML_VALUE;
        }

        @Override
        public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
            map.forEach(request::setAttribute);
        }
    };

    final Cas30ResponseView view = new Cas30ResponseView(true, encoder, servicesManager,
            "attribute", viewDelegated, true);
    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);
    return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:Cas30ResponseViewTests.java

示例2: contentNegotiatingViewResolver

import org.springframework.web.servlet.View; //导入依赖的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

示例3: generateGradePDF

import org.springframework.web.servlet.View; //导入依赖的package包/类
@GetMapping
public ModelAndView generateGradePDF(@RequestParam("identifier") String identifier,
                                     ModelMap modelMap,
                                     UriComponentsBuilder uriComponentsBuilder) throws Exception {

    View view = new GradePDFView();
    Grade grade = gradeService.getForValidation(identifier);
    if (grade == null) {
        return new ModelAndView("error/404");
    }
    modelMap.addAttribute("grade", grade);
    modelMap.addAttribute(
            "validationLink",
            uriComponentsBuilder
                    .path("/public/grade")
                    .queryParam("identifier", identifier)
                    .build()
                    .toString()
    );
    ModelAndView modelAndView = new ModelAndView(view);
    return modelAndView;
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:23,代码来源:PublicGradeController.java

示例4: uploadFile

import org.springframework.web.servlet.View; //导入依赖的package包/类
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public View uploadFile(@RequestParam("file") MultipartFile file) {
	try {
		InputStream input = file.getInputStream();
		this.messageManagementService.importFromExcel(input);
	} catch (Exception e) {
		LOG.error("error on uploading messages", e);
		return new RedirectView("../files.html?uploadSuccess=no&message=" + e.getMessage().toString());
	}
	return new RedirectView("../files.html?uploadSuccess=yes");
}
 
开发者ID:namics,项目名称:spring-i18n-support,代码行数:12,代码来源:FileController.java

示例5: addAnswer

import org.springframework.web.servlet.View; //导入依赖的package包/类
@PostMapping("topic")
public View addAnswer(@RequestParam("content") String content, @RequestParam("code") String code,
                      @RequestParam("id_topic") String id_topic, @RequestParam("id_user") String id_user,
                      HttpServletRequest request) {
    Answer answer = new Answer();
    answer.setContent(content);

    // I know that it can be blank field, but I did it on purpose to find out about Optionals:
    if (Objects.equals(code, ""))
        answer.setCode(null);
    else
        answer.setCode(code);
    answer.setCreatedDate(LocalDateTime.now());
    answer.setUseful(false);
    answer.setTopic(topicRepository.findTopicById(Long.valueOf(id_topic)));
    answer.setUser(userRepository.getUserById(Long.parseLong(id_user)));

    answerRepository.save(answer);
    String contextPath = request.getContextPath();
    return new RedirectView(contextPath + "/topic/" + id_topic);
}
 
开发者ID:plkpiotr,项目名称:forum,代码行数:22,代码来源:TopicController.java

示例6: addTask

import org.springframework.web.servlet.View; //导入依赖的package包/类
@PostMapping("profile")
public View addTask(@RequestParam("category") String category, @RequestParam("title") String title,
                    @RequestParam("content") String content, @RequestParam("code") String code,
                    @RequestParam("id_user") String id_user, HttpServletRequest request) {
    Topic topic = new Topic();
    topic.setCategory(category);

    // I know that it can be blank field, but I did it on purpose to find out about Optionals:
    if (Objects.equals(code, ""))
        topic.setCode(null);
    else
        topic.setCode(code);

    topic.setContent(content);
    topic.setTitle(title);
    topic.setCreatedDate(LocalDateTime.now());
    topic.setUser(userRepository.getUserById(Long.parseLong(id_user)));

    topicRepository.save(topic);
    String contextPath = request.getContextPath();
    return new RedirectView(contextPath + "/profile");
}
 
开发者ID:plkpiotr,项目名称:forum,代码行数:23,代码来源:ProfileController.java

示例7: registerUser

import org.springframework.web.servlet.View; //导入依赖的package包/类
@PostMapping("register")
public View registerUser(@RequestParam("username") String username, @RequestParam("password") String password,
                         @RequestParam("introduction") String introduction, HttpServletRequest request) {
    String contextPath = request.getContextPath();
    User user = new User();
    if (userRepository.getUserByUsername(username) == null) {
        user.setUsername(username);
        // I know that it can be blank field, but I did it on purpose to find out about Optionals:
        if (Objects.equals(introduction, ""))
            user.setIntroduction(null);
        else
            user.setIntroduction(introduction);
        user.setPassword(password);
        user.setPassword(passwordEncoder.encode(password));
        user.setCreatedDate(LocalDateTime.now());
        userRepository.save(user);
        return new RedirectView(contextPath + "/login");
    } else
        return new RedirectView(contextPath + "/register");
}
 
开发者ID:plkpiotr,项目名称:forum,代码行数:21,代码来源:RegisterController.java

示例8: getModelAndView

import org.springframework.web.servlet.View; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ModelAndView getModelAndView(Object returnValue) {
	if (returnValue instanceof ModelAndView) {
		return (ModelAndView) returnValue;
	}
	else if (returnValue instanceof Model) {
		return new ModelAndView().addAllObjects(((Model) returnValue).asMap());
	}
	else if (returnValue instanceof Map) {
		return new ModelAndView().addAllObjects((Map<String, Object>) returnValue);
	}
	else if (returnValue instanceof View) {
		return new ModelAndView(returnValue);
	}
	else if (returnValue instanceof String) {
		return new ModelAndView((String) returnValue);
	}
	else if (returnValue == null) {
		return new ModelAndView();
	}
	else {
		throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AnnotationMethodHandlerExceptionResolver.java

示例9: resolveModelAndView

import org.springframework.web.servlet.View; //导入依赖的package包/类
@Override
public org.springframework.web.servlet.ModelAndView resolveModelAndView(Method handlerMethod,
		Class<?> handlerType,
		Object returnValue,
		ExtendedModelMap implicitModel,
		NativeWebRequest webRequest) {
	if (returnValue instanceof MySpecialArg) {
		return new org.springframework.web.servlet.ModelAndView(new View() {
			@Override
			public String getContentType() {
				return "text/html";
			}

			@Override
			public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
					throws Exception {
				response.getWriter().write("myValue");
			}

		});
	}
	return UNRESOLVED;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:PortletAnnotationControllerTests.java

示例10: createView

import org.springframework.web.servlet.View; //导入依赖的package包/类
/**
 * Overridden to implement check for "redirect:" prefix.
 * <p>Not possible in {@code loadView}, since overridden
 * {@code loadView} versions in subclasses might rely on the
 * superclass always creating instances of the required view class.
 * @see #loadView
 * @see #requiredViewClass
 */
@Override
protected View createView(String viewName, Locale locale) throws Exception {
	// If this resolver is not supposed to handle the given view,
	// return null to pass on to the next resolver in the chain.
	if (!canHandle(viewName, locale)) {
		return null;
	}
	// Check for special "redirect:" prefix.
	if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
		String redirectUrl = viewName.substring(REDIRECT_URL_PREFIX.length());
		RedirectView view = new RedirectView(redirectUrl, isRedirectContextRelative(), isRedirectHttp10Compatible());
		return applyLifecycleMethods(viewName, view);
	}
	// Check for special "forward:" prefix.
	if (viewName.startsWith(FORWARD_URL_PREFIX)) {
		String forwardUrl = viewName.substring(FORWARD_URL_PREFIX.length());
		return new InternalResourceView(forwardUrl);
	}
	// Else fall back to superclass implementation: calling loadView.
	return super.createView(viewName, locale);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:UrlBasedViewResolver.java

示例11: resolveViewName

import org.springframework.web.servlet.View; //导入依赖的package包/类
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
	RequestAttributes attrs = RequestContextHolder.getRequestAttributes();
	Assert.isInstanceOf(ServletRequestAttributes.class, attrs);
	List<MediaType> requestedMediaTypes = getMediaTypes(((ServletRequestAttributes) attrs).getRequest());
	if (requestedMediaTypes != null) {
		List<View> candidateViews = getCandidateViews(viewName, locale, requestedMediaTypes);
		View bestView = getBestView(candidateViews, requestedMediaTypes, attrs);
		if (bestView != null) {
			return bestView;
		}
	}
	if (this.useNotAcceptableStatusCode) {
		if (logger.isDebugEnabled()) {
			logger.debug("No acceptable view found; returning 406 (Not Acceptable) status code");
		}
		return NOT_ACCEPTABLE_VIEW;
	}
	else {
		logger.debug("No acceptable view found; returning null");
		return null;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ContentNegotiatingViewResolver.java

示例12: getCandidateViews

import org.springframework.web.servlet.View; //导入依赖的package包/类
private List<View> getCandidateViews(String viewName, Locale locale, List<MediaType> requestedMediaTypes)
		throws Exception {

	List<View> candidateViews = new ArrayList<View>();
	for (ViewResolver viewResolver : this.viewResolvers) {
		View view = viewResolver.resolveViewName(viewName, locale);
		if (view != null) {
			candidateViews.add(view);
		}
		for (MediaType requestedMediaType : requestedMediaTypes) {
			List<String> extensions = this.contentNegotiationManager.resolveFileExtensions(requestedMediaType);
			for (String extension : extensions) {
				String viewNameWithExtension = viewName + "." + extension;
				view = viewResolver.resolveViewName(viewNameWithExtension, locale);
				if (view != null) {
					candidateViews.add(view);
				}
			}
		}
	}
	if (!CollectionUtils.isEmpty(this.defaultViews)) {
		candidateViews.addAll(this.defaultViews);
	}
	return candidateViews;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:ContentNegotiatingViewResolver.java

示例13: resolveViewName

import org.springframework.web.servlet.View; //导入依赖的package包/类
@Override
public View resolveViewName(String viewName, Locale locale) throws BeansException {
	ApplicationContext context = getApplicationContext();
	if (!context.containsBean(viewName)) {
		if (logger.isDebugEnabled()) {
			logger.debug("No matching bean found for view name '" + viewName + "'");
		}
		// Allow for ViewResolver chaining...
		return null;
	}
	if (!context.isTypeMatch(viewName, View.class)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Found matching bean for view name '" + viewName +
					"' - to be ignored since it does not implement View");
		}
		// Since we're looking into the general ApplicationContext here,
		// let's accept this as a non-match and allow for chaining as well...
		return null;
	}
	return context.getBean(viewName, View.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:BeanNameViewResolver.java

示例14: handleReturnValue

import org.springframework.web.servlet.View; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		return;
	}
	else if (returnValue instanceof View){
		View view = (View) returnValue;
		mavContainer.setView(view);
		if (view instanceof SmartView) {
			if (((SmartView) view).isRedirectView()) {
				mavContainer.setRedirectModelScenario(true);
			}
		}
	}
	else {
		// should not happen
		throw new UnsupportedOperationException("Unexpected return type: " +
				returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ViewMethodReturnValueHandler.java

示例15: getModelAndView

import org.springframework.web.servlet.View; //导入依赖的package包/类
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);
	if (!mavContainer.isViewReference()) {
		mav.setView((View) mavContainer.getView());
	}
	if (model instanceof RedirectAttributes) {
		Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
		HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
		RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
	}
	return mav;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:RequestMappingHandlerAdapter.java


注:本文中的org.springframework.web.servlet.View类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。