本文整理汇总了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;
}