thymeleaf 相关问题

Thymeleaf是一个XML / XHTML / HTML5模板引擎(可扩展到其他格式),可以在Web和非Web环境中工作。它更适合在Web应用程序的视图层提供XHTML / HTML5,它甚至可以在脱机环境中处理任何XML文件。它提供了一个可选模块,用于与Spring MVC集成,因此您可以在使用此技术的应用程序中将其用作JSP的完全替代,即使使用HTML5也是如此。

尝试使用 PathVariable 传递参数会导致错误无法将类型“java.lang.String”的值转换为所需类型“java.lang.Long”

我正在为我的父母构建这个简单的应用程序,以便更轻松地“检查清单”已支付的账单。我自己构建了它(免费,呃),作为

回答 1 投票 0

org.springframework.web.HttpRequestMethodNotSupportedException:不支持请求方法“POST”

我正在开发我的Java、Springboot、React和Thymeleaf应用程序的登录模块,并且遇到`org.springframework.web.HttpRequestMethodNotSupportedException:请求方法'POST'...

回答 1 投票 0

Thymeleaf 无法识别 Lombok getter 和 setter

Lombok 插件已安装。使用 IntelliJ 15。模型结构显示了 getter 和 setter,但我从 Thymeleaf 收到以下错误。 错误: bean 类的无效属性“postTitle”[...

回答 2 投票 0

Spring - 无法解析 MVC“视图”thymeleaf

我有一个简单的HomeController.class: 包 com.example.tacos; 导入 org.springframework.stereotype.Controller; 导入 org.springframework.web.bind.annotation.GetMapping; @控制器 公开课

回答 9 投票 0

Spring Boot中的文件上传:上传、验证和异常处理

我希望能够将图像上传到服务器,优雅地处理错误和异常,并以表单向用户显示错误消息,并且最好仅使用现有的准系统...

回答 3 投票 0

如何将变量包含在hx-vals中?

我有一个用于搜索的输入标签。 现在我在 div 中有一个 hx-get 。 &...

回答 1 投票 0

如何在 Spring Boot 中返回模板(thymeleaf)并将其解析到特定端点

简短:我想使用 Thymeleaf 模板index.html,但 url 指向thanks.html。 深入:我试图提交表单将我的用户带到页面http://localhost:8080/thanks.html。我

回答 1 投票 0

使用 spring/thymeleaf 迭代数据库中的对象时出现问题

最近我开始为 Splitwise 创建克隆项目,问题是我无法从数据库中迭代我的用户,即使它们存在并且是在控制台中编写的。 https://github.com/

回答 1 投票 0

如何将 ModelAttribute 从 HTML (Thymeleaf) 发送到控制器

我的图书控制器: @GetMapping("/{id}") public String showBook(Model model, @PathVariable("id") Integer id, @ModelAttribute("review") Review review){ if(预订服务。

回答 1 投票 0

我如何将 ModelAttribute 从 HTML(Thymeleaf) 发送到控制器

我的图书控制器: @GetMapping("/{id}") public String showBook(Model model, @PathVariable("id") Integer id, @ModelAttribute("review") Review review){ 如果(

回答 1 投票 0

在 Thymeleaf 中使用 servletUriComponentsBuilder 进行分页片段

我正在使用带有 Maven 和 Java 17 的 Spring boot 3.1.4,正在编写 Wim Deblauwe 的书 #Taming Thymeleaf。我已经到达第 249 页,现在正在尝试实现分页。虽然我成功了

回答 1 投票 0

我尝试创建可编辑的表格。我有七列的表格。我想编辑表格并提交给控制器

问题: 我尝试检索我拥有的所有数据,然后编辑表中的列日期和/或用餐时间。 如代码所示,我有两种方法,一种用于 GET,一种用于提交

回答 1 投票 0

从 jar 运行时,Spring Boot 给出“TemplateInputException:解析模板时出错”

我有一个应用程序,在 IntelliJ 中或通过 gradle bootRun 启动时可以完美运行。 但是,如果我执行 gradle bootRepackage 然后尝试运行生成的 jar,我最终会得到: 2014-12-02 21:4...

回答 10 投票 0

无法将“java.lang.String”类型的值转换为嵌套的所需类型“java.lang.Long”,除了 java.lang.NumberFormatException 对于输入字符串“null”

我遇到此错误,不知道还需要解决什么问题。我只是想让用户单击“rsvp”按钮并将其与单击的用户 ID 一起注册到数据库...

回答 2 投票 0

解析模板时出错,模板可能不存在,或者可能无法被任何配置的模板解析器访问

我有以下控制器: @控制器 公共类配置控制器{ @GetMapping("/") 公共字符串索引(){ 返回“配置”; } } 然而,我收到了...

回答 4 投票 0

Thymeleaf 无法识别 CSS 文件

我正在尝试使用 Thymeleaf html 链接 CSS 样式表。当我运行应用程序并在线测试时,没有应用任何样式。 下面是我的html代码 我正在尝试使用 Thymeleaf html 链接 CSS 样式表。当我运行应用程序并在线测试时,没有应用任何样式。 下面是我的html代码 <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Homepage</title> <link th:href="@{/css/main.css}" rel="stylesheet"> </head> <body class="custom-bg"> <nav> <ul> <li> <a th:href="@{/admin/homepage}"> Home </a> </li> <li> <a th:href="@{/welcome}"> Page 1 </a> </li> <li> <a th:href="@{/admin/new/employees}"> Create New Employee </a> </li> <li> <form th:action="@{/logout}" method="post" > <button type="submit">Logout</button> </form> </li> </ul> </nav> <h1>Admin homepage</h1> <h2>Welcome,</h2> <h3 th:text="${employee.getFirstName()} + ' ' + ${employee.getLastName()}">Name</h3> </body> </html> 这是我的 CSS 文件 * { color: aqua; } .custom-bg { background-color: deeppink; } body { background-color: deeppink; } 我的文件结构的图像 我在网上和 thymeleaf 文档中进行了研究,我发现默认文件路径/结构与我的相同,并且 css 文件应该被识别并能够使用下面的链接 href 进行调用。 <link th:href="@{/css/main.css}" rel="stylesheet"> 但是,当我使用此链接 href(如下)时,IDE intelliSense 发现那里有一个文件,但当我运行应用程序时,没有应用样式。 <link th:href="@{../static/css/main.css}" rel="stylesheet"> 我还发现 Spring Security 可能会导致问题。所以我将文件路径添加到我的过滤器链配置文件中。 @Bean SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> { auth.requestMatchers("/admin/**") .hasAuthority("ADMIN"); auth.requestMatchers("/manager/**") .hasAuthority("MANAGER"); auth.requestMatchers("/employee/**") .hasAuthority("EMPLOYEE"); auth.requestMatchers("employees") .hasAnyAuthority("MANAGER", "EMPLOYEE"); auth.requestMatchers("/css/**") .permitAll(); auth.requestMatchers("/js/**") .permitAll(); auth.requestMatchers("/images/**") .permitAll(); auth.anyRequest().authenticated(); }); http.httpBasic(Customizer.withDefaults()); http.formLogin() .loginProcessingUrl("/login") .successHandler(loginSuccessHandler) .permitAll() .and() .logout() .deleteCookies("JSESSIONID"); http.csrf((AbstractHttpConfigurer::disable)); return http.build(); } 最后,当我加载网页时,控制台给出了这个错误。我提供了两个版本,具体取决于我使用的链接 href。 (上面提供)。 我是否需要在控制器中映射 GET 请求来访问 CSS 文件? 2023-09-29T14:48:19.939+01:00 WARN 4772 --- [nio-8080-exec-7] o.s.web.servlet.PageNotFound : No mapping for GET /static/css/main.css 2023-09-29T14:59:52.447+01:00 WARN 14708 --- [nio-8080-exec-7] o.s.web.servlet.PageNotFound : No mapping for GET /css/main.css 编辑 我想显示我的整个配置类,以防出现我看不到的问题。 package com.sparta.tma.config; import com.sparta.tma.services.LoginSuccessHandler; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.ProviderManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @Configuration @AllArgsConstructor @EnableWebSecurity @EnableWebMvc public class SecurityConfiguration { @Autowired private LoginSuccessHandler loginSuccessHandler; @Bean SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> { auth.requestMatchers("/admin/**") .hasAuthority("ADMIN"); auth.requestMatchers("/manager/**") .hasAuthority("MANAGER"); auth.requestMatchers("/employee/**") .hasAuthority("EMPLOYEE"); auth.requestMatchers("employees") .hasAnyAuthority("MANAGER", "EMPLOYEE"); auth.requestMatchers("/css/**") .permitAll(); auth.requestMatchers("/static/**") .permitAll(); auth.requestMatchers("/resources/**") .permitAll(); auth.anyRequest().authenticated(); }); http.httpBasic(Customizer.withDefaults()); http.formLogin() .loginProcessingUrl("/login") .successHandler(loginSuccessHandler) .permitAll() .and() .logout() .deleteCookies("JSESSIONID"); http.csrf((AbstractHttpConfigurer::disable)); return http.build(); } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean public AuthenticationManager authManager(UserDetailsService detailsService) { DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); provider.setPasswordEncoder(passwordEncoder()); provider.setUserDetailsService(detailsService); return new ProviderManager(provider); } } 当您在浏览器中打开 CSS 文件时,会发生什么? 404 或重定向到您的应用程序页面? 我也遇到了一些挑战并通过这种方式解决了。 CSS文件的路径在我的项目中:/src/main/resources/static/main.css 模板 <link th:href="@{/static/main.css}" rel="stylesheet" /> 应用程序属性 spring.mvc.static-path-pattern=/static/** 拦截器配置 @Configuration public class InterceptorsConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addPathPatterns("/**") .excludePathPatterns("/static/**"); } }

回答 1 投票 0

有没有更好的方法将变量传递到视图层而不是使用控制器?

每次创建控制器路由时,我都必须将变量传递给视图层: @配置 公共类配置{ @Value("${api.url}") 私有字符串 apiUrl; @豆 ...

回答 1 投票 0

根据java中的模板将xml解析为pdf

我需要根据模板将xml解析为pdf,该模板不需要再次生成战争并在我的服务器中重新部署。 我使用 JAXB 将 xml 解析为我的 java 实体,之后我想要...

回答 2 投票 0

Thymeleaf strings.arraySplit 不起作用

我也有类似的问题,请大家提出建议。 我正在使用这个获取数据 我也有类似的问题,请大家指点一下。 我正在使用这个获取数据 <tbody th:each="map : ${InsDashboardData}"> <tr th:each="mapEntry : ${map}"> <td th:text="${mapEntry.key}"></td> <td></td> <td>[[${mapEntry.value}]]</td> </tr> 但我需要我的程序名称的拆分数据。作为计算机应用硕士(MCA),摄入量为 500。我正在尝试使用下面的代码,但出现错误。 表达式 [#strings.arraySplit(${insData}, '@@@')] @21:EL1043E:意外的标记。预期为“rparen())”,但结果为“lcurly({)” <tbody th:each="map : ${InsDashboardData}"> <tr th:each="mapEntry : ${map}"> <td th:with="insData=${mapEntry.key}" th:each="item : ${#strings.arraySplit(${insData}, '@@@')}" th:text="${#strings.arraySplit(item,'#')[0]}"></td> <td th:text="${#strings.arraySplit(item,'#')[1]}"></td> <td>[[${mapEntry.value}]]</td> </tr> 我并不完全清楚这个要求,但是,我想我可以在这里看到语法错误。内部变量不需要再次添加$。 th:each =“项目:$ {#strings.arraySplit(insData,'@@@')}” 你必须使用这行代码才能工作: ${#strings.arraySplit(mapEntry.key, '@@@')[0]} - 获取@@@之前的值。 ${#strings.arraySplit(mapEntry.key, '@@@')[1]} - 获取@@@之后的值。 用于测试的控制器代码: @Controller public class DemoController { @GetMapping("/") public ModelAndView save() { ModelAndView modelAndView = new ModelAndView(); Map<String,String> map = new HashMap<>(); map.put("Master of Computer Application@@@500", "316"); map.put("Bachelor of Computer Application@@@1000", "11"); modelAndView.setViewName("index"); modelAndView.addObject("InsDashboardData", map); return modelAndView; } } 更新了 HTML: <html xmlns:th="https://thymeleaf.org"> <head> <style> table, th, td { border: 1px solid; } </style> </head> <table> <thead> <tr> <th>Programme Name</th> <th>Intake Capacity</th> <th>Final Admission</th> </tr> </thead> <tbody th:each="map : ${InsDashboardData}"> <tr th:each="mapEntry : ${map}"> <td th:text="${#strings.arraySplit(mapEntry.key, '@@@')[0]}"></td> <td th:text="${#strings.arraySplit(mapEntry.key, '@@@')[1]}"></td> <td>[[${mapEntry.value}]]</td> </tr> </table> </html> 输出:

回答 2 投票 0

Spring - BindingResult 和 bean 名称“form”的普通目标对象都不能作为请求属性

我正在使用 Java,Spring 使用 Thymeleaf。 我创建了一个带有几个输入的表单,IntelliJ 抱怨它无法解析 Thymeleaf 对象属性。当我尝试加载 w...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.