- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.springframework.web.bind.support.WebExchangeDataBinder
类的一些代码示例,展示了WebExchangeDataBinder
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebExchangeDataBinder
类的具体详情如下:
包路径:org.springframework.web.bind.support.WebExchangeDataBinder
类名称:WebExchangeDataBinder
[英]Specialized org.springframework.validation.DataBinder to perform data binding from URL query params or form data in the request data to Java objects.
[中]专门组织。springframework。验证。DataBinder执行从URL查询参数或请求数据中的表单数据到Java对象的数据绑定。
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() throws Exception {
this.testBean = new TestBean();
this.binder = new WebExchangeDataBinder(this.testBean, "person");
this.binder.registerCustomEditor(ITestBean.class, new TestBeanPropertyEditor());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Protected method to obtain the values for data binding. By default this
* method delegates to {@link #extractValuesToBind(ServerWebExchange)}.
*/
protected Mono<Map<String, Object>> getValuesToBind(ServerWebExchange exchange) {
return extractValuesToBind(exchange);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Combine query params and form data for multipart form data from the body
* of the request into a {@code Map<String, Object>} of values to use for
* data binding purposes.
* @param exchange the current exchange
* @return a {@code Mono} with the values to bind
* @see org.springframework.http.server.reactive.ServerHttpRequest#getQueryParams()
* @see ServerWebExchange#getFormData()
* @see ServerWebExchange#getMultipartData()
*/
public static Mono<Map<String, Object>> extractValuesToBind(ServerWebExchange exchange) {
MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
Mono<MultiValueMap<String, String>> formData = exchange.getFormData();
Mono<MultiValueMap<String, Part>> multipartData = exchange.getMultipartData();
return Mono.zip(Mono.just(queryParams), formData, multipartData)
.map(tuple -> {
Map<String, Object> result = new TreeMap<>();
tuple.getT1().forEach((key, values) -> addBindValue(result, key, values));
tuple.getT2().forEach((key, values) -> addBindValue(result, key, values));
tuple.getT3().forEach((key, values) -> addBindValue(result, key, values));
return result;
});
}
代码示例来源:origin: spring-projects/spring-framework
private void validate(Object target, Object[] validationHints, MethodParameter param,
BindingContext binding, ServerWebExchange exchange) {
String name = Conventions.getVariableNameForParameter(param);
WebExchangeDataBinder binder = binding.createDataBinder(exchange, target, name);
binder.validate(validationHints);
if (binder.getBindingResult().hasErrors()) {
throw new WebExchangeBindException(param, binder.getBindingResult());
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Bind query params, form data, and or multipart form data to the binder target.
* @param exchange the current exchange.
* @return a {@code Mono<Void>} when binding is complete
*/
public Mono<Void> bind(ServerWebExchange exchange) {
return getValuesToBind(exchange)
.doOnNext(values -> doBind(new MutablePropertyValues(values)))
.then();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testMultipart() throws Exception {
MultipartBean bean = new MultipartBean();
WebExchangeDataBinder binder = new WebExchangeDataBinder(bean);
MultiValueMap<String, Object> data = new LinkedMultiValueMap<>();
data.add("name", "bar");
data.add("someList", "123");
data.add("someList", "abc");
data.add("someArray", "dec");
data.add("someArray", "456");
data.add("part", new ClassPathResource("org/springframework/http/codec/multipart/foo.txt"));
data.add("somePartList", new ClassPathResource("org/springframework/http/codec/multipart/foo.txt"));
data.add("somePartList", new ClassPathResource("org/springframework/http/server/reactive/spring.png"));
binder.bind(exchangeMultipart(data)).block(Duration.ofMillis(5000));
assertEquals("bar", bean.getName());
assertEquals(Arrays.asList("123", "abc"), bean.getSomeList());
assertArrayEquals(new String[] {"dec", "456"}, bean.getSomeArray());
assertEquals("foo.txt", bean.getPart().filename());
assertEquals(2, bean.getSomePartList().size());
assertEquals("foo.txt", bean.getSomePartList().get(0).filename());
assertEquals("spring.png", bean.getSomePartList().get(1).filename());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithCommaSeparatedStringArray() throws Exception {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("stringArray", "bar");
formData.add("stringArray", "abc");
formData.add("stringArray", "123,def");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertEquals("Expected all three items to be bound", 3, this.testBean.getStringArray().length);
formData.remove("stringArray");
formData.add("stringArray", "123,def");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertEquals("Expected only 1 item to be bound", 1, this.testBean.getStringArray().length);
}
代码示例来源:origin: spring-projects/spring-framework
return binder.bind(exchange)
.doOnError(bindingResultMono::onError)
.doOnSuccess(aVoid -> {
validateIfApplicable(binder, parameter);
BindingResult errors = binder.getBindingResult();
model.put(BindingResult.MODEL_KEY_PREFIX + name, errors);
model.put(name, value);
})
.then(Mono.fromCallable(() -> {
BindingResult errors = binder.getBindingResult();
if (adapter != null) {
return adapter.fromPublisher(errors.hasErrors() ?
代码示例来源:origin: spring-projects/spring-framework
@Test
public void requestMappingHandlerAdapter() throws Exception {
ApplicationContext context = loadConfig(WebFluxConfig.class);
String name = "requestMappingHandlerAdapter";
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
assertEquals(13, readers.size());
ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);
assertHasMessageReader(readers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
assertHasMessageReader(readers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
assertHasMessageReader(readers, forClass(String.class), TEXT_PLAIN);
assertHasMessageReader(readers, forClass(Resource.class), IMAGE_PNG);
assertHasMessageReader(readers, forClass(Message.class), new MediaType("application", "x-protobuf"));
assertHasMessageReader(readers, multiValueMapType, APPLICATION_FORM_URLENCODED);
assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_XML);
assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_JSON);
assertHasMessageReader(readers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile"));
assertHasMessageReader(readers, forClass(TestBean.class), null);
WebBindingInitializer bindingInitializer = adapter.getWebBindingInitializer();
assertNotNull(bindingInitializer);
WebExchangeDataBinder binder = new WebExchangeDataBinder(new Object());
bindingInitializer.initBinder(binder);
name = "webFluxConversionService";
ConversionService service = context.getBean(name, ConversionService.class);
assertSame(service, binder.getConversionService());
name = "webFluxValidator";
Validator validator = context.getBean(name, Validator.class);
assertSame(validator, binder.getValidator());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a {@link WebExchangeDataBinder} to apply data binding and
* validation with on the target, command object.
* @param exchange the current exchange
* @param target the object to create a data binder for
* @param name the name of the target object
* @return the created data binder
* @throws ServerErrorException if {@code @InitBinder} method invocation fails
*/
public WebExchangeDataBinder createDataBinder(ServerWebExchange exchange, @Nullable Object target, String name) {
WebExchangeDataBinder dataBinder = new WebExchangeDataBinder(target, name);
if (this.initializer != null) {
this.initializer.initBinder(dataBinder);
}
return initDataBinder(dataBinder, exchange);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception {
this.binder.setIgnoreUnknownFields(false);
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("_postProcessed", "visible");
formData.add("postProcessed", "on");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertTrue(this.testBean.isPostProcessed());
formData.remove("postProcessed");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertFalse(this.testBean.isPostProcessed());
}
代码示例来源:origin: spring-projects/spring-framework
private void updateBindingContext(BindingContext context, ServerWebExchange exchange) {
Map<String, Object> model = context.getModel().asMap();
model.keySet().stream()
.filter(name -> isBindingCandidate(name, model.get(name)))
.filter(name -> !model.containsKey(BindingResult.MODEL_KEY_PREFIX + name))
.forEach(name -> {
WebExchangeDataBinder binder = context.createDataBinder(exchange, model.get(name), name);
model.put(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
});
}
代码示例来源:origin: spring-projects/spring-framework
private void validateIfApplicable(WebExchangeDataBinder binder, MethodParameter parameter) {
for (Annotation ann : parameter.getParameterAnnotations()) {
Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann));
if (hints != null) {
Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
binder.validate(validationHints);
}
else {
binder.validate();
}
}
}
}
代码示例来源:origin: org.springframework/spring-web
/**
* Bind query params, form data, and or multipart form data to the binder target.
* @param exchange the current exchange.
* @return a {@code Mono<Void>} when binding is complete
*/
public Mono<Void> bind(ServerWebExchange exchange) {
return getValuesToBind(exchange)
.doOnNext(values -> doBind(new MutablePropertyValues(values)))
.then();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFieldPrefixCausesFieldReset() throws Exception {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("_postProcessed", "visible");
formData.add("postProcessed", "on");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertTrue(this.testBean.isPostProcessed());
formData.remove("postProcessed");
this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
assertFalse(this.testBean.isPostProcessed());
}
代码示例来源:origin: org.springframework/spring-web-reactive
return binder.bind(exchange)
.doOnError(bindingResultMono::onError)
.doOnSuccess(aVoid -> {
validateIfApplicable(binder, parameter);
BindingResult errors = binder.getBindingResult();
model.put(BindingResult.MODEL_KEY_PREFIX + name, errors);
model.put(name, value);
})
.then(Mono.fromCallable(() -> {
BindingResult errors = binder.getBindingResult();
if (adapter != null) {
return adapter.fromPublisher(errors.hasErrors() ?
代码示例来源:origin: org.springframework/spring-web-reactive
protected void validate(Object target, Object[] validationHints,
MethodParameter param, BindingContext binding, ServerWebExchange exchange) {
String name = Conventions.getVariableNameForParameter(param);
WebExchangeDataBinder binder = binding.createDataBinder(exchange, target, name);
binder.validate(validationHints);
if (binder.getBindingResult().hasErrors()) {
throw new WebExchangeBindException(param, binder.getBindingResult());
}
}
代码示例来源:origin: org.springframework/spring-web-reactive
/**
* Create the data binder instance.
*/
protected WebExchangeDataBinder createBinderInstance(Object target, String objectName) {
return new WebExchangeDataBinder(target, objectName);
}
代码示例来源:origin: org.springframework/spring-web-reactive
private void addBindingResult(HandlerResult result, ServerWebExchange exchange) {
BindingContext context = result.getBindingContext();
Map<String, Object> model = context.getModel().asMap();
model.keySet().stream()
.filter(name -> isBindingCandidate(name, model.get(name)))
.filter(name -> !model.containsKey(BindingResult.MODEL_KEY_PREFIX + name))
.forEach(name -> {
WebExchangeDataBinder binder = context.createDataBinder(exchange, model.get(name), name);
model.put(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
});
}
代码示例来源:origin: org.springframework/spring-web-reactive
protected void validateIfApplicable(WebExchangeDataBinder binder, MethodParameter parameter) {
Annotation[] annotations = parameter.getParameterAnnotations();
for (Annotation ann : annotations) {
Validated validAnnot = AnnotationUtils.getAnnotation(ann, Validated.class);
if (validAnnot != null || ann.annotationType().getSimpleName().startsWith("Valid")) {
Object hints = (validAnnot != null ? validAnnot.value() : AnnotationUtils.getValue(ann));
Object hintArray = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
binder.validate(hintArray);
}
}
}
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!