当前位置: 首页>>代码示例>>Java>>正文


Java DataBinder.getTarget方法代码示例

本文整理汇总了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);
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:48,代码来源:SendController.java

示例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();
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:76,代码来源:DataBinderDeserializer.java

示例3: DataBinderWrapper

import org.springframework.validation.DataBinder; //导入方法依赖的package包/类
public DataBinderWrapper(final DataBinder binder) {
    super(binder.getTarget(), binder.getObjectName());
}
 
开发者ID:backpaper0,项目名称:spring-boot-sandbox,代码行数:4,代码来源:Snake2CamelModelAttributeMethodProcessor.java


注:本文中的org.springframework.validation.DataBinder.getTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。