- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 thymeleaf 形式以及单值 react 数据流。使用 spring boot 2.1.3、thymeleaf 3.0.11 和 webflux。我的 POJO 是:
@Getter
@Setter
@NoArgsConstructor
public class RecipeCommand {
private String id;
private String description;
}
Controller 是:
@GetMapping("/recipe/{id}/update")
public String updateRecipe(Model model, @PathVariable String id){
Mono<RecipeCommand> recipeCommandMono = recipeService.getRecipeCommandById(id);
model.addAttribute("recipe", recipeCommandMono);
return "recipes/recipeform";
}
其中recipes/recipeform是 thymeleaf 形式来更新菜谱:
<form th:object="${recipe}" th:action="@{/post}" method="post">
<input type="hidden" th:field="*{id}"/>
应用程序运行,但在尝试更新配方时出现以下错误:
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'id' of bean class [reactor.core.publisher.MonoOnAssembly]: Bean property 'id' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
知道如何将 thymeleaf 形式与 react 流一起使用。
POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gabriel</groupId>
<artifactId>spring-recipe</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-recipe</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>popper.js</artifactId>
<version>1.14.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
最佳答案
您正在尝试将 Mono 传递给您的模板。相反,您可以使用 IReactiveDataDriverContextVariable 对象包装 Mono 。 IReactiveDataDriverContextVariable 与 Flux 配合使用,因此您应该使用 flux() 方法将 Mono 转换为 Flux。
@GetMapping("/recipe/{id}/update")
public String updateRecipe(Model model, @PathVariable String id){
Mono<RecipeCommand> recipeCommandMono = recipeService.getRecipeCommandById(id);
IReactiveDataDriverContextVariable recipe = new ReactiveDataDriverContextVariable(recipeCommandMono.flux(), 1);
model.addAttribute("recipes", recipe);
return "recipes/recipeform";
}
更改 thymeleaf 部分(变量食谱现在是异步列表)
<div th:each="recipe : ${recipes}">
<form th:object="${recipe}" th:action="@{/post}" method="post">
<input type="hidden" th:field="*{id}"/>
关于java - 当尝试使用 react 数据时,我得到了 bean 类 [reactor.core.publisher.MonoOnAssembly] 的无效属性 'id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59555315/
我正在尝试使用 thymeleaf 形式以及单值 react 数据流。使用 spring boot 2.1.3、thymeleaf 3.0.11 和 webflux。我的 POJO 是: @Gette
我是一名优秀的程序员,十分优秀!