在HTML中,我似乎无法从Thymeleaf访问范围内的代理数据类Singleton
我的数据类
@Document(collection = "networker")
open class Networker(
@Id
var id: String? = null,
@TextIndexed
@Indexed(direction = IndexDirection.ASCENDING)
var name: String? = null,
....然后我的@Configuration豆
@Bean
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
fun networker(): Networker {
return Networker()
}然后,我得到正确的记录,并添加模型的态度
@GetMapping(value = ["index"])
@ModelAttribute(value = "networker")
fun profileView(model: Model): String {
val authentication = SecurityContextHolder.getContext().authentication
val username: String = authentication.name
networker = networkerRepository.findBySecurityUserName(username)
model.addAttribute("networker", networker)
model.addAttribute("networkerSettings", networkerSettings)
return "profile/index"
}我试过
<tbody th:object="${networker}">th.text="${@networker.name}",我没有得到任何内容,但是编译没有抱怨th:object="${#servletContext.getAttribute(networker)}"这样的东西,但是它们都没有显示我可以编辑的数据。
请给我看一些工作样本。
发布于 2019-12-08 15:38:53
解决方案很简单,我需要
@Bean
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)我只需要用@Controller注释@SessionAttributes("networker"),从HTML th:object="${networker}"的调用就能很好地工作了。
https://stackoverflow.com/questions/59212547
复制相似问题