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


Java ModelAndView類代碼示例

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


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

示例1: exception

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuffer sb = new StringBuffer();
    sb.append("Exception during execution of Spring Security application!   ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append(" root cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:21,代碼來源:ErrorController.java

示例2: userLogin

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@RequestMapping(value="/dologin.html")
public ModelAndView userLogin(@Valid User loginuser, BindingResult result){
	
	ModelAndView mv = new ModelAndView();
	
	// BindingResult����洢���DZ?��֤�Ľ��
	if(result.hasErrors() == true){ // ��֤����
		mv.setViewName("login");    // ��ת���?ҳ��
		return mv;
	}
	
	// ����Service����ʵ�ֵ�¼��֤
	User user = userService.login(loginuser.getUsercode(), 
								  loginuser.getUserpassword());
	//User user = null;
	// ���user��Ϊnull����¼�ɹ�
	if(user != null){
		mv.setViewName("frame");
	}else{
		mv.addObject("error", "用戶名或密碼錯誤 ");
		mv.setViewName("login");
	}
	return mv;
}
 
開發者ID:Marui0325,項目名稱:y2t187test,代碼行數:25,代碼來源:UserControl.java

示例3: exception

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuilder sb = new StringBuilder();
    sb.append("Exception during execution of Spring Security application!   ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append(" root cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:21,代碼來源:ErrorController.java

示例4: centerfans

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@RequestMapping("/center/fans")
@Menu(type = "apps" , subtype = "user" , name="fans" , access = false)
public ModelAndView centerfans(HttpServletRequest request , HttpServletResponse response, @Valid String orgi, @Valid String q) {
	ModelAndView view = request(super.createAppsTempletResponse("/apps/user/centerfans")) ;
	String userid = super.getUser(request).getId() ;
	Pageable page = new PageRequest(super.getP(request), super.getPs(request), new Sort(Direction.DESC, "createtime")) ;
	Page<Fans> fansList = fansRes.findByUser(userid, page) ;
	
	List<String> userids = new ArrayList<String>();
	for(Fans fan : fansList){
		userids.add(fan.getCreater()) ;
	}
	if(userids.size()>0){
		view.addObject("fansList",new PageImpl<User>(userRes.findAll(userids), page, fansList.getTotalElements()) ) ;
	}
	
    return view;
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:19,代碼來源:UserController.java

示例5: login

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@GetMapping(value = "/login")
public ModelAndView login(
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    logger.info("******login(error): {} ***************************************", error);
    logger.info("******login(logout): {} ***************************************", logout);

    ModelAndView model = new ModelAndView();
    if (error != null) {
        model.addObject("error", "Invalid username and password!");
    }

    if (logout != null) {
        model.addObject("message", "You've been logged out successfully.");
    }
    model.setViewName("login");

    return model;

}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:22,代碼來源:LoginController.java

示例6: handleRequestInternal

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    MediaFile dir = mediaFileService.getMediaFile(id);
    List<MediaFile> files = mediaFileService.getChildrenOf(dir, true, false, true, false);

    Map<String, Object> map = new HashMap<String, Object>();
    if (!files.isEmpty()) {
        map.put("defaultArtist", files.get(0).getArtist());
        map.put("defaultAlbum", files.get(0).getAlbumName());
        map.put("defaultYear", files.get(0).getYear());
        map.put("defaultGenre", files.get(0).getGenre());
    }
    map.put("allGenres", JaudiotaggerParser.getID3V1Genres());

    List<Song> songs = new ArrayList<Song>();
    for (int i = 0; i < files.size(); i++) {
        songs.add(createSong(files.get(i), i));
    }
    map.put("id", id);
    map.put("songs", songs);

    return new ModelAndView("editTags","model",map);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:26,代碼來源:EditTagsController.java

示例7: search

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
/**
 * @param type Type of data sought
 * @param q Search for a phrase
 * @param page Page number
 * @param pageSize Number of items per page
 * @param modelMap {@link ModelMap}
 * @return The ModelAndView for a list of users (or a list of movies( in the future ))
 */
@GetMapping(value = "/search")
public ModelAndView search(
        @RequestParam final String type,
        @RequestParam final String q,
        @RequestParam(defaultValue = "1") final int page,
        @RequestParam(defaultValue = "1") final int pageSize,
        final ModelMap modelMap
) {
    modelMap.addAttribute("type", type);
    modelMap.addAttribute("q", q);
    modelMap.addAttribute("page", page);
    modelMap.addAttribute("pageSize", pageSize);

    return new ModelAndView("users", modelMap);
}
 
開發者ID:JonkiPro,項目名稱:REST-Web-Services,代碼行數:24,代碼來源:SearchController.java

示例8: processForgotPassword

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@PostMapping(value="/forgotpassword/process", produces="application/json")
public ModelAndView processForgotPassword(ModelMap model, @RequestParam("emailaddress") String email) {
	
	User user = null;
	try {
		user = userService.doesUserExist(email);
	} catch (UserNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	if(user != null) {
		
	}	
	model.addAttribute("message", "An email notification is sent to the registered email address.");
	return new ModelAndView("forgotpassword", model);
}
 
開發者ID:PacktPublishing,項目名稱:Building-Web-Apps-with-Spring-5-and-Angular,代碼行數:17,代碼來源:UserAccountController.java

示例9: resolveException

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    if (ex instanceof UserApiException) {
        UserApiException apiException = (UserApiException) ex;
        UserExceptionData userExceptionData = new UserExceptionData();
        userExceptionData.setCode(apiException.getCode());
        userExceptionData.setMessage(apiException.getMessage());
        UserExceptionInfo userExceptionInfo = new UserExceptionInfo();
        userExceptionInfo.setExceptionClass(ex.getClass().getName());
        userExceptionInfo.setUserExceptionData(userExceptionData);

        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        response.setContentType("application/json;charset=UTF-8");
        try {
            response.getWriter().write(JSON.toJSONString(userExceptionInfo));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return new ModelAndView();
    }
    throw new RuntimeException(ex);
}
 
開發者ID:richterplus,項目名稱:spring-cloud-sample,代碼行數:23,代碼來源:ControllerExceptionHandler.java

示例10: showMyRecord

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@RequestMapping("showMyRecord")
public ModelAndView showMyRecord(HttpServletRequest request, ModelAndView mav) throws Exception {
	System.out.println("showMyRecord 컨트롤러 입성!");
	Member mvo = (Member) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	String userId = mvo.getUserId();
	System.out.println("showMyRecord 유저아이디:" + userId);
	List<String> rightList = memberService.selectRightNo(userId);
	List<String> wrongList = memberService.selectWrongNo(userId);
	AnswerResult answerResult = memberService.selectMyRecord(userId);
	int myRanking = memberService.selectMyRanking(userId);
	mav.addObject("rightList", rightList);
	mav.addObject("wrongList", wrongList);
	mav.addObject("answerResult", answerResult);
	mav.addObject("myRanking", myRanking);
	mav.setViewName("/member/showMyRecord");

	return mav;
}
 
開發者ID:INSUPARK83,項目名稱:way_learning,代碼行數:19,代碼來源:MemberController.java

示例11: verifyOKWithState

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@Test
public void verifyOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(
            "GET",
            CONTEXT
            + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + '?' + OAuthConstants.CODE + '=' + SERVICE_TICKET + '&' + OAuthConstants.STATE + '='
            + STATE, map.get("callbackUrl"));
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:22,代碼來源:OAuth20CallbackAuthorizeControllerTests.java

示例12: exception

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView exception(final Throwable throwable, final Model model) {
    logger.error("Exception during execution of SpringSecurity application", throwable);
    StringBuffer sb = new StringBuffer();
    sb.append("Exception during execution of Spring Security application!  ");

    sb.append((throwable != null && throwable.getMessage() != null ? throwable.getMessage() : "Unknown error"));

    if (throwable != null && throwable.getCause() != null) {
        sb.append("\n\nroot cause: ").append(throwable.getCause());
    }
    model.addAttribute("error", sb.toString());

    ModelAndView mav = new ModelAndView();
    mav.addObject("error", sb.toString());
    mav.setViewName("error");

    return mav;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:21,代碼來源:ErrorController.java

示例13: handleRequestInternal

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();

    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    Player player = playerService.getPlayer(request, response);
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        return new ModelAndView(new RedirectView("notFound"));
    }

    map.put("playlist", playlist);
    map.put("user", user);
    map.put("player", player);
    map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
    map.put("partyMode", userSettings.isPartyModeEnabled());

    return new ModelAndView("playlist","model",map);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:23,代碼來源:PlaylistController.java

示例14: blogForUsername

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@RequestMapping(value = "/blog/{username}", method = RequestMethod.GET)
    public ModelAndView blogForUsername(@PathVariable String username,
                                        @RequestParam("pageSize") Optional<Integer> pageSize,
                                        @RequestParam("page") Optional<Integer> page) {
        // Evaluate page size. If requested parameter is null, return initial
        // page size
        int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
        // Evaluate page. If requested parameter is null or less than 0 (to
        // prevent exception), return initial size. Otherwise, return value of
        // param. decreased by 1.
        int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;

        ModelAndView modelAndView = new ModelAndView();
        User user = userService.findByUsername(username);
        if (user == null) {
            modelAndView.setViewName("404");
        } else {
            Page<Post> posts = postService.findByUserOrderedByDatePageable(user, new PageRequest(evalPage, evalPageSize));
            Pager pager = new Pager(posts.getTotalPages(), posts.getNumber(), BUTTONS_TO_SHOW);

//            modelAndView.addObject("posts", postService.findNLatestPostsForUser(10, user));
            modelAndView.addObject("posts", posts);
            modelAndView.addObject("selectedPageSize", evalPageSize);
            modelAndView.addObject("pageSizes", PAGE_SIZES);
            modelAndView.addObject("pager", pager);
            modelAndView.addObject("user", user);
            modelAndView.setViewName("posts");
        }
        return modelAndView;
    }
 
開發者ID:reljicd,項目名稱:spring-boot-blog,代碼行數:31,代碼來源:BlogController.java

示例15: verifyNoRedirectUri

import org.springframework.web.servlet.ModelAndView; //導入依賴的package包/類
@Test
public void verifyNoRedirectUri() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.AUTHORIZE_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.ERROR_VIEW, modelAndView.getViewName());
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:12,代碼來源:OAuth20AuthorizeControllerTests.java


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