当前位置: 首页>>代码示例>>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;未经允许,请勿转载。