本文整理汇总了Java中org.springframework.validation.DataBinder.getTarget方法的典型用法代码示例。如果您正苦于以下问题:Java DataBinder.getTarget方法的具体用法?Java DataBinder.getTarget怎么用?Java DataBinder.getTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.DataBinder
的用法示例。
在下文中一共展示了DataBinder.getTarget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
/**
* Process the send form.
*/
@PostMapping
public ModelAndView create(final HttpServletRequest req,
final RedirectAttributes redirectAttributes)
throws IOException, FileUploadException {
if (!ServletFileUpload.isMultipartContent(req)) {
throw new IllegalStateException("No multipart request!");
}
// Create encryptionKey and initialization vector (IV) to encrypt data
final KeyIv encryptionKey = messageService.newEncryptionKey();
// secret shared with receiver using the link - not stored in database
final String linkSecret = messageService.newRandomId();
final DataBinder binder = initBinder();
final List<SecretFile> tmpFiles = handleStream(req, encryptionKey, binder);
final EncryptMessageCommand command = (EncryptMessageCommand) binder.getTarget();
final BindingResult errors = binder.getBindingResult();
if (!errors.hasErrors()
&& command.getMessage() == null
&& (tmpFiles == null || tmpFiles.isEmpty())) {
errors.reject(null, "Neither message nor files submitted");
}
if (errors.hasErrors()) {
return new ModelAndView(FORM_SEND_MSG, binder.getBindingResult().getModel());
}
final String senderId = messageService.storeMessage(command.getMessage(), tmpFiles,
encryptionKey, HashCode.fromString(linkSecret).asBytes(), command.getPassword(),
Instant.now().plus(command.getExpirationDays(), ChronoUnit.DAYS));
redirectAttributes
.addFlashAttribute("messageSent", true)
.addFlashAttribute("message", command.getMessage());
return
new ModelAndView("redirect:/send/" + senderId)
.addObject("linkSecret", linkSecret);
}
示例2: deserialize
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
/**
* Deserializes JSON content into Map<String, String> format and then uses a
* Spring {@link DataBinder} to bind the data from JSON message to JavaBean
* objects.
* <p/>
* It is a workaround for issue
* https://jira.springsource.org/browse/SPR-6731 that should be removed from
* next gvNIX releases when that issue will be resolved.
*
* @param parser Parsed used for reading JSON content
* @param ctxt Context that can be used to access information about this
* deserialization activity.
*
* @return Deserializer value
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object deserialize(JsonParser parser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonToken t = parser.getCurrentToken();
MutablePropertyValues propertyValues = new MutablePropertyValues();
// Get target from DataBinder from local thread. If its a bean
// collection
// prepares array index for property names. Otherwise continue.
DataBinder binder = (DataBinder) ThreadLocalUtil
.getThreadVariable(BindingResult.MODEL_KEY_PREFIX
.concat("JSON_DataBinder"));
Object target = binder.getTarget();
// For DstaBinderList instances, contentTarget contains the final bean
// for binding. DataBinderList is just a simple wrapper to deserialize
// bean wrapper using DataBinder
Object contentTarget = null;
if (t == JsonToken.START_OBJECT) {
String prefix = null;
if (target instanceof DataBinderList) {
prefix = binder.getObjectName().concat("[")
.concat(Integer.toString(((Collection) target).size()))
.concat("].");
// BeanWrapperImpl cannot create new instances if generics
// don't specify content class, so do it by hand
contentTarget = BeanUtils
.instantiateClass(((DataBinderList) target)
.getContentClass());
((Collection) target).add(contentTarget);
}
else if (target instanceof Map) {
// TODO
LOGGER.warn("Map deserialization not implemented yet!");
}
Map<String, String> obj = readObject(parser, ctxt, prefix);
propertyValues.addPropertyValues(obj);
}
else {
LOGGER.warn("Deserialization for non-object not implemented yet!");
return null; // TODO?
}
// bind to the target object
binder.bind(propertyValues);
// Note there is no need to validate the target object because
// RequestResponseBodyMethodProcessor.resolveArgument() does it on top
// of including BindingResult as Model attribute
// For DAtaBinderList the contentTarget contains the final bean to
// make the binding, so we must return it
if (contentTarget != null) {
return contentTarget;
}
return binder.getTarget();
}
示例3: DataBinderWrapper
import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
public DataBinderWrapper(final DataBinder binder) {
super(binder.getTarget(), binder.getObjectName());
}