Tag: thymeleaf

Thymeleaf选择选项重置为默认值

在html中有一个搜索表单: 选项中的默认值是“名字”。 当我选择,让我们说,通过手机搜索,按“搜索”并得到结果页面,表单选项被重置为默认值。 但我需要它来保持我选择的变体,在这种情况下,它是“手机”。 什么必须在HTML中进行更改? 填写表格: 收到搜索结果后,“选项”应该保持“手机”: html代码: 在JSP + Spring标签的情况下,很容易解决: 但是Thymeleaf令人困惑

Spring MVC Thymeleaf Kotlin

我试图将窗体传递给控制器​​,但对象是空的(看起来像从默认构造函数而不是forms获取值)。 不知道为什么@Valid不起作用。 码: 端点 @PostMapping(“/add”) fun addDevice(@Valid @ModelAttribute device: Device, model: ModelMap): ModelAndView { deviceRepository.save(device) return ModelAndView(“redirect:/devices/all”, model) } 实体: @Entity data class Device( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) val id: Int? = null, @NotNull val name: String? = “”, @Min(10) @Max(30) val price: Int? = null, @Size(min = 8) val secretPhrase: String? = “” ) […]

将thymeleaf版本2.14迁移到3.0不能找到消息属性

Thymeleaf版本2.14正确拾取message.properties文件。 迁移到3.0之后,它给错误了hello.MESSAGE_en_US ??。 但在javacode通过自动装配messsagesource messageSource.getMessage( "hello.MESSAGE",null, Locale.getDefault()) ->Hello App 项目结构 src/main/ -java -com.cando -controllers -resources -messages_en.properties -spring.properties -webapp -WEB-INF -templates -index.html 的index.html <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <title>Helllo</title> </head> <body> <p th:text="#{hello.MESSAGE}">Hello App!</p> </body> </html> messages_en.properties hello.MESSAGE=Hello App 配置 @Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource(); resourceBundleMessageSource.setBasename("messages"); resourceBundleMessageSource.setBasename("spring"); return resourceBundleMessageSource; }