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