本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}