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


Java BindingResult.getTarget方法代碼示例

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


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

示例1: removeBindingResultIfNecessary

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
private void removeBindingResultIfNecessary(Object key, Object value) {
	if (key instanceof String) {
		String attributeName = (String) key;
		if (!attributeName.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
			String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + attributeName;
			BindingResult bindingResult = (BindingResult) get(bindingResultKey);
			if (bindingResult != null && bindingResult.getTarget() != value) {
				remove(bindingResultKey);
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:BindingAwareModelMap.java

示例2: save

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
/**
 * Save element to database
 * 
 * @param type
 *            the domain type
 * @param request
 *            current HttpServletRequest
 * @param page
 *            current page
 * @param size
 *            current page size
 * @param model
 *            current model
 * 
 * @return edit/view template name
 */
@RequestMapping(value = "${crudadmin.url}/post/{type}/{size}/{page}", method = RequestMethod.POST)
public String save(@PathVariable String type, @PathVariable int size, @PathVariable int page,
		HttpServletRequest request, Model model) {
	try {
		CrudAdminRepository repoAdmin = repositoryMap.get(type);
		ServletRequestParameterPropertyValues values = new ServletRequestParameterPropertyValues(request);
		final BindingResult result = repoAdmin.getWebDataBinder(values).getBindingResult();
		Object object = result.getTarget();
		String idString = values.getPropertyValue("id").getValue().toString();
		idString = idString.isEmpty() ? null : idString;
		Object id = null;
		try {
			// existing object ?
			if (idString != null) {
				id = idSerializer.fromString(idString, repoAdmin.getIdType());
				repoAdmin.getId().set(object, id);
			}
			// save
			repoAdmin.getRepositoryObjectSerializable().save(object);
			idString =  getStringFromId(repoAdmin.getId().get(object), repoAdmin);			
			return "redirect:/" + crudAdminProperties.getUrl() + "/view/" + repoAdmin.getDomainTypeNameLowerCase()
					+ "/" + size + "/" + page + "/" + idString+'/';
		} catch (Exception transactionException) {
			Throwable rootCause = transactionException;
			while (rootCause.getCause() != null) {
				rootCause = rootCause.getCause();
			}
			if (rootCause instanceof ConstraintViolationException) {
				ConstraintViolationException constraintViolationException = (ConstraintViolationException) rootCause;
				String message = "";
				for (ConstraintViolation<?> constraintValidation : constraintViolationException
						.getConstraintViolations()) {
					message += "<br/><b>" + constraintValidation.getPropertyPath().toString() + "</b> "
							+ constraintValidation.getMessage();
				}
				return doEdit(type, idString, size, page, message, model);
			}
			throw transactionException;
		}

	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
開發者ID:qlefevre,項目名稱:crud-admin-spring-boot-starter,代碼行數:61,代碼來源:CrudAdminController.java


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