本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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: 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);
}
示例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);
}
示例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);
}
示例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;
}
示例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"));
}
示例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;
}
示例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);
}
示例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;
}
示例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