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


Java ModelAndView.addObject方法代碼示例

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


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

示例1: handleError

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@ExceptionHandler(ProductNotFoundException.class)
public ModelAndView handleError(HttpServletRequest req, ProductNotFoundException exception) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("invalidProductId", exception.getProductId());
    mav.addObject("exception", exception);
    mav.addObject("url", req.getRequestURL()+"?"+req.getQueryString());
    mav.setViewName("productNotFound");
    return mav;
}
 
開發者ID:TomirKlos,項目名稱:Webstore,代碼行數:10,代碼來源:ProductController.java

示例2: 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

示例3: createNewUser

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@RequestMapping(value = "/registration", method = RequestMethod.POST)
public ModelAndView createNewUser(@Valid User user, BindingResult bindingResult) {
	ModelAndView modelAndView = new ModelAndView();
	User userExists = userService.findUserByEmail(user.getEmail());
	if (userExists != null) {
		bindingResult.rejectValue("email", "error.user",
				"There is already a user registered with the email provided");
	}
	if (bindingResult.hasErrors()) {
		modelAndView.setViewName("registration");
	} else {
		userService.saveUser(user);
		modelAndView.addObject("successMessage", "User has been registered successfully");
		modelAndView.addObject("user", new User());
		modelAndView.setViewName("registration");

	}
	return modelAndView;
}
 
開發者ID:garydamm,項目名稱:idea-forge,代碼行數:20,代碼來源:LoginController.java

示例4: 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

示例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: 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

示例7: main

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@RequestMapping(value = "/cabList", method = RequestMethod.GET)
public ModelAndView main() {
	ModelAndView modelAndView = new ModelAndView();
	modelAndView.addObject("cabs", superService.getCabs());
	modelAndView.setViewName("cabList");
	return modelAndView;
}
 
開發者ID:zaleslaw,項目名稱:Spring-Tutorial,代碼行數:8,代碼來源:JSPHandling.java

示例8: newPost

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@RequestMapping(value = "/newPost", method = RequestMethod.GET)
public ModelAndView newPost(Principal principal) {
    ModelAndView modelAndView = new ModelAndView();
    User user = userService.findByUsername(principal.getName());
    Post post = new Post();
    post.setUser(user);
    modelAndView.addObject("post", post);
    modelAndView.setViewName("postForm");
    return modelAndView;
}
 
開發者ID:reljicd,項目名稱:spring-boot-blog,代碼行數:11,代碼來源:PostController.java

示例9: IndexView

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@RequestMapping(value = "/")
public ModelAndView IndexView( ModelMap model ) {
	List<UndergroundLine> undergroundLinesList = undergroundLinesRepository.findAll();
	List<UndergroundStation> undergroundStationsList = undergroundStationsRepository.findAll();

	ModelAndView modelAndView = new ModelAndView("index");
	modelAndView.addObject("undergroundLinesList", undergroundLinesList);
	modelAndView.addObject("undergroundStationsList", undergroundStationsList);
	
	return modelAndView;
}
 
開發者ID:dcaav,項目名稱:mongoDBLeafletViewer-master,代碼行數:12,代碼來源:SpringControllerViewer.java

示例10: myEvents

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@GetMapping("/my")
public ModelAndView myEvents() {
    CalendarUser currentUser = userContext.getCurrentUser();
    Integer currentUserId = currentUser.getId();
    ModelAndView result = new ModelAndView("events/my", "events", calendarService.findForUser(currentUserId));
    result.addObject("currentUser", currentUser);
    return result;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:9,代碼來源:EventsController.java

示例11: receive

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@RequestMapping(value = "/receive",method = RequestMethod.GET)
public ModelAndView receive() throws  Exception {
    System.err.println("--------------> receive <----------------");
    List<String> msg = new ArrayList<String>();
    msg = consumers.receive();
    String msg1 = consumerForHive.receive();
    ModelAndView mv = new ModelAndView();
    mv.addObject("msg",msg);
    mv.setViewName("kafka_receive");
    return  mv;
}
 
開發者ID:wanghan0501,項目名稱:WiFiProbeAnalysis,代碼行數:12,代碼來源:DataUploadController.java

示例12: processUnauthenticatedException

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@ExceptionHandler({UnauthorizedException.class})
public ModelAndView processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) {
    ModelAndView mv = new ModelAndView();
    mv.addObject("exception", e.getMessage());
    mv.setViewName("/common/error.ftl");
    return mv;
}
 
開發者ID:melonlee,項目名稱:LazyAdmin,代碼行數:8,代碼來源:UnauthorizedExceptionHandler.java

示例13: register

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@GetMapping("/register")
public ModelAndView register(ModelAndView mv) {
    mv.setViewName("client/register");
    mv.addObject("registry", new BasicClientInfo());

    return mv;
}
 
開發者ID:PacktPublishing,項目名稱:OAuth-2.0-Cookbook,代碼行數:8,代碼來源:ClientController.java

示例14: myEventsByEmail

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
private ModelAndView myEventsByEmail(CalendarUser user) {
    String email = user.getEmail();
    ModelAndView result = new ModelAndView("events/my", "events", calendarService.findForUser(email));
    result.addObject("currentUser", user);
    return result;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:7,代碼來源:EventsController.java

示例15: handleRequestInternal

import org.springframework.web.servlet.ModelAndView; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView result = new ModelAndView();
    result.addObject("album", request.getParameter("album"));
    return result;
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:7,代碼來源:AllmusicController.java


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