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


Java Model.addAttribute方法代碼示例

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


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

示例1: saveOrUpdate

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/save.d", produces = "application/json;charset=UTF-8")
public String saveOrUpdate(MultipartHttpServletRequest multipartReq, MoFeatured moFeatured, Model model) {
    try {
        if (moFeatured.getPicType() == 3) {
            String bigPics = StringUtils.defaultIfEmpty(moFeatured.getBigPics(), "").replace(",,", "");
            moFeatured.setBigPics(StringUtils.stripEnd(StringUtils.stripStart(bigPics, ","), ","));
        } else {
            String pics = StringUtils.defaultIfEmpty(moFeatured.getPics(), "").replace(",,", "");
            moFeatured.setPics(StringUtils.stripEnd(StringUtils.stripStart(pics, ","), ","));
        }
        moFeaturedService.saveOrUpdate(multipartReq, moFeatured);
        model.addAttribute("rstCode", 0);
    } catch (Exception e) {
        model.addAttribute("rstCode", 1);
    }
    return "/moFeatured/save";
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:18,代碼來源:MoFeaturedController.java

示例2: exception

import org.springframework.ui.Model; //導入方法依賴的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: play

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/photos", method = GET)
public String play(Model model) {
    model.addAttribute("parentId", SharedUtils.randomNegativeId());
    model.addAttribute("fileuploading", fmService.getFileUploadingScript());
    model.addAttribute("fileuploaded", fmService.getFileUploadedScript());
    return POSTS_PLAY_VIEW;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:8,代碼來源:PostsUploadController.java

示例4: input

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping("pim-plan-input")
public String input(@RequestParam(value = "id", required = false) Long id,
        Model model) {
    if (id != null) {
        PimPlan pimPlan = pimPlanManager.get(id);
        model.addAttribute("model", pimPlan);
    }

    return "pim/pim-plan-input";
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:11,代碼來源:PimPlanController.java

示例5: list

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping("sale-info-list")
public String list(@ModelAttribute Page page,
        @RequestParam Map<String, Object> parameterMap, Model model) {
    String tenantId = tenantHolder.getTenantId();
    List<PropertyFilter> propertyFilters = PropertyFilter
            .buildFromMap(parameterMap);
    propertyFilters.add(new PropertyFilter("EQS_tenantId", tenantId));
    page = saleInfoManager.pagedQuery(page, propertyFilters);

    model.addAttribute("page", page);

    return "sale/sale-info-list";
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:14,代碼來源:SaleInfoController.java

示例6: list

import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
 * 當前輸入模型列表
 */
@RequestMapping("list")
public String list(HttpServletRequest request, Model model){
	AliyunLog.addActionLog(getSiteId(), "進入CMS模式下自定義輸入模型列表");
	
	model.addAttribute("list", inputModelService.getInputModelListForSession());
	return "inputModel/list";
}
 
開發者ID:xnx3,項目名稱:wangmarket,代碼行數:11,代碼來源:InputModelController.java

示例7: update

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/update", method = RequestMethod.GET)
public String update(Model model) {
    Iterable<User> users = usersService.findAll();
    Iterable<UserRole> roles = userRolesService.findAll();
    Iterable<Address> address = addressService.findAll();

    model.addAttribute("address", address);
    model.addAttribute("users", users);
    model.addAttribute("roles", roles);
    return "administratorSite/usersManager/update";
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:12,代碼來源:UpdateUsers.java

示例8: login

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpServletResponse response, Model model) {
    HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
    httpSessionSecurityContextRepository.loadContext(holder);

    try {
        // 使用提供的證書認證用戶
        List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN");
        Authentication auth = new UsernamePasswordAuthenticationToken(request.getParameter("username"), request.getParameter("password"), authorities);
        SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(auth));

        // 認證用戶
        if(!auth.isAuthenticated())
            throw new CredentialException("用戶不能夠被認證");
    } catch (Exception ex) {
        // 用戶不能夠被認證,重定向回登錄頁
        logger.info(ex);
        return "login";
    }

    // 從會話得到默認保存的請求
    DefaultSavedRequest defaultSavedRequest = (DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST");
    // 為令牌請求生成認證參數Map
    Map<String, String> authParams = getAuthParameters(defaultSavedRequest);
    AuthorizationRequest authRequest = new DefaultOAuth2RequestFactory(clientDetailsService).createAuthorizationRequest(authParams);
    authRequest.setAuthorities(AuthorityUtils.createAuthorityList("ROLE_USER", "ROLE_ADMIN"));
    model.addAttribute("authorizationRequest", authRequest);

    httpSessionSecurityContextRepository.saveContext(SecurityContextHolder.getContext(), holder.getRequest(), holder.getResponse());
    return "authorize";
}
 
開發者ID:chaokunyang,項目名稱:microservices-event-sourcing,代碼行數:32,代碼來源:LoginController.java

示例9: popupSiteUpdate

import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
 * 彈出框,站點信息修改
 * 網站設置-修改聯係信息,如地址、QQ等
 */
@RequestMapping("popupSiteUpdate.do")
public String popupSiteUpdate(Model model){
	AliyunLog.addActionLog(getSiteId(), "彈出彈出框,顯示站點信息修改");
	
	model.addAttribute("site", getSite());
	return "site/popup_site";
}
 
開發者ID:xnx3,項目名稱:wangmarket,代碼行數:12,代碼來源:SiteController.java

示例10: references

import org.springframework.ui.Model; //導入方法依賴的package包/類
private void references(Model model){
	List<Integer> deptIds = new ArrayList<>();
	List<Department> depts = departmentServiceImpl.readDepartments().getNow(new ArrayList<>());
	Iterator<Department> iterate = depts.iterator();
	while(iterate.hasNext()){
		deptIds.add(iterate.next().getId());
	}
	model.addAttribute("deptIds", deptIds);
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:10,代碼來源:EmployeeController.java

示例11: input

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping("vote-info-input")
public String input(@RequestParam(value = "id", required = false) Long id,
        Model model) {
    if (id != null) {
        VoteInfo voteInfo = voteInfoManager.get(id);
        model.addAttribute("model", voteInfo);
    }

    return "vote/vote-info-input";
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:11,代碼來源:VoteInfoController.java

示例12: readOne

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "read", method = RequestMethod.POST)
public String readOne(@RequestParam("id") String id, Model model) {
    CouponCode couponCode = couponCodesService.findOne(Long.parseLong(id));

    if (couponCode == null) {
        model.addAttribute("msg", "not found");
        return "administratorSite/couponCodesManager/read";
    }
    model.addAttribute("couponCode", couponCode);
    return "administratorSite/couponCodesManager/read";
}
 
開發者ID:xSzymo,項目名稱:Spring-web-shop-project,代碼行數:12,代碼來源:ReadCouponCodes.java

示例13: showFaq

import org.springframework.ui.Model; //導入方法依賴的package包/類
@SuppressWarnings("SameReturnValue")
@RequestMapping
public String showFaq(Model model){

    model.addAttribute("LXG - Faq","title");
    return "faq";

}
 
開發者ID:Recks11,項目名稱:theLXGweb,代碼行數:9,代碼來源:FaqController.java

示例14: list

import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping("book-borrow-list")
public String list(@ModelAttribute Page page,
        @RequestParam Map<String, Object> parameterMap, Model model) {
    List<PropertyFilter> propertyFilters = PropertyFilter
            .buildFromMap(parameterMap);
    page = bookBorrowManager.pagedQuery(page, propertyFilters);

    model.addAttribute("page", page);

    return "book/book-borrow-list";
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:12,代碼來源:BookBorrowController.java

示例15: index

import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
 * 首頁 映射/和/index路徑
 *
 * @return
 * @throws Exception
 */
@RequestMapping({ "/", "/index" })
public String index(Model model) throws Exception {
	List<Product> productList = productService.getProductList();
	model.addAttribute("productList", productList);
	return "index";
}
 
開發者ID:honghailiang,項目名稱:SpringMango,代碼行數:13,代碼來源:PageController.java


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