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


Java BindingResult.hasFieldErrors方法代碼示例

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


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

示例1: createLinkPost

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value = "/add/link", method = POST)
public String createLinkPost(@Valid PostDTO postDTO, BindingResult result,
                             CurrentUser currentUser, RedirectAttributes attributes, Model model,
                             HttpServletRequest request) throws DuplicatePostNameException {
    PagePreviewDTO pagePreview =
            (PagePreviewDTO) WebUtils.getSessionAttribute(request, "pagePreview");

    model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
    model.addAttribute("postFormType", "link");

    if (!isDuplicatePost(postDTO, null)) {
        if (result.hasErrors()) {
            model.addAttribute("hasLink", true);
            model.addAttribute("hasCarousel", true);
            model.addAttribute("pagePreview", pagePreview);
            if (result.hasFieldErrors("postTitle")) {
                postDTO.setPostTitle(pagePreview.getTitle());
            }
            model.addAttribute("postDTO", postDTO);
            return ADMIN_LINK_ADD_VIEW;
        } else {

            if (postDTO.getHasImages()) {
                if (postDTO.getDisplayType() != PostDisplayType.LINK) {
                    postDTO.setPostImage(
                            pagePreview.getImages().get(postDTO.getImageIndex()).src);
                } else
                    postDTO.setPostImage(null);
            }

            postDTO.setPostSource(PostUtils.createPostSource(postDTO.getPostLink()));
            postDTO.setPostName(PostUtils.createSlug(postDTO.getPostTitle()));
            postDTO.setUserId(currentUser.getId());
            postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));

            request.setAttribute("postTitle", postDTO.getPostTitle());
            Post post = postService.add(postDTO);

            postDTO.setPostId(post.getPostId());
            post.setPostMeta(jsoupService.createPostMeta(postDTO));

            // All links are saved as PUBLISHED so no _isPublished_ status check on new Links
            if (applicationSettings.getSolrEnabled())
                postDocService.addToIndex(post);

            // Links are included in Posts A-to-Z Listing
            fmService.createPostAtoZs();

            webUI.addFeedbackMessage(attributes, FEEDBACK_POST_LINK_ADDED);
            return "redirect:/admin/posts";
        }
    } else {
        result.reject("global.error.post.name.exists", new Object[]{postDTO.getPostTitle()}, "post name exists");
        model.addAttribute("hasLink", true);
        model.addAttribute("hasCarousel", true);
        model.addAttribute("pagePreview", pagePreview);
        return ADMIN_LINK_ADD_VIEW;
    }
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:60,代碼來源:AdminPostsController.java


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