标签: thymeleaf

注销与Spring和Thymeleaf的链接

根据官方示例(Secure Web Content),我必须使用表单和按钮,目的是使用Spring Security执行注销.有没有办法使用Thymeleaf链接而不是按钮?

spring spring-mvc spring-security thymeleaf

16
推荐指数
5
解决办法
1万
查看次数

飞碟,Thymeleaf和春天

我有一个Spring应用程序,需要构建对PDF生成的支持.我正在考虑将飞碟与Thymeleaf一起使用来渲染PDF.但是,我找不到有关将飞碟与Thymeleaf一起使用的更多信息.有没有其他人一起使用这些技术?

pdf spring flying-saucer thymeleaf

16
推荐指数
1
解决办法
9557
查看次数

将CSRF放入Spring 4.0.3 + Spring Security 3.2.3 + Thymeleaf 2.1.2中的Headers中

我有以下代码:

<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <!-- default header name is X-CSRF-TOKEN -->
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
    <title>Fileupload Test</title>
</head>
<body>

<p th:text="${msg}"></p>

<form action="#" th:action="@{/fileUpload}" method="post" enctype="multipart/form-data">
    <input type="file" name="myFile"/>
    <input type="submit"/>
</form>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我收到错误HTTP 403:

在请求参数'_csrf'或标题'X-CSRF-TOKEN'上找到无效的CSRF令牌'null'

如果我使用此行,CSRF正在工作:

<form action="#" th:action="@{/fileUpload} + '?' + ${_csrf.parameterName} + '=' + ${_csrf.token}" method="post" enctype="multipart/form-data">
Run Code Online (Sandbox Code Playgroud)

但是如果我使用标题,我怎样才能实现工作CSRF?

security spring csrf thymeleaf

16
推荐指数
3
解决办法
9190
查看次数

SpringBoot - UTF-8在messages.properties中不起作用

有什么问题?

我无法在UTF-8中显示我在messages.properties中收到的消息.

一个例子

<h1 id="logo">Electrónico</h1>
Run Code Online (Sandbox Code Playgroud)

这工作没问题但是当我尝试使用这样的消息源时

<h1 id="logo" th:text="#{titulo.electronico}">Electrónico</h1>
Run Code Online (Sandbox Code Playgroud)

我得到"Electr nico"而不是Electrónico

这是我的配置

application.properties

spring.messages.encoding=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
Run Code Online (Sandbox Code Playgroud)

的pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <start-class>demo.Demo</start-class>
    <java.version>1.7</java.version>
</properties>
Run Code Online (Sandbox Code Playgroud)

演示课

@SpringBootApplication
public class Demo {

    public static void main(String[] args) {
        SpringApplication.run(Demo.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

ServletInitializer.class

@Configuration
public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Demo.class);
    }

    @Bean
    public ServletRegistrationBean h2servletRegistration() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
        registration.addUrlMappings("/console/*");
        return registration;
    }

    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    CharacterEncodingFilter characterEncodingFilter() {
      CharacterEncodingFilter filter = …
Run Code Online (Sandbox Code Playgroud)

spring utf-8 thymeleaf

16
推荐指数
4
解决办法
2万
查看次数

基于上下文数据显示活动导航

我在Thymeleaf模板中有以下分隔的片段.

<ul class="nav nav-tabs">
    <li role="presentation"><a href="/">Freight Invoices</a></li>
    <li role="presentation"><a href="/processed">Processed Invoices</a></li>
    <li role="presentation"><a href="/postingrules">Posting Rules</a></li>
    <li role="presentation" class="active"><a href="/settings">Settings</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我想在主动导航元素中添加一个"活动"类 - 但在Thymyleaf中似乎很难实现.有什么建议?

java navigation spring jsp thymeleaf

16
推荐指数
4
解决办法
1万
查看次数

Thymeleaf + CSS + SpringBoot

我有CSS和Thymeleaf的问题.

在我的Spring启动应用程序中,我有这样的结构:

  • src/main/resource/static/css(用于css文件)
  • src/main/resource/static/templates(用于html文件)

现在,我的html页面名为ErrorPage,css文件名为Layout.css,使用Thymeleaf,我在ErrorPage的头部:

<link href="../css/Layout.css" th:href="@{css/Layout.css}" type="text/css" />
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

我究竟做错了什么?

css3 thymeleaf spring-boot

16
推荐指数
1
解决办法
3万
查看次数

在编辑时选择百日咳多重

我完全改变了这个问题,因为它的一部分 Avnish的帮助下得到了回答!汤姆把我送到了正确的方向,谢谢汤姆!

我的问题是我不知道如何告诉Thymeleaf在编辑时预先选择对象元素.

让我演示给你看:

看起来像这样

此解决方案有效:

<select class="form-control" id="parts" name="parts" multiple="multiple">
    <option th:each="part : ${partsAtribute}"
            th:selected="${servisAttribute.parts.contains(part)}"
            th:value="${part.id}"
            th:text="${part.name}">Part name</option>
</select>
Run Code Online (Sandbox Code Playgroud)

我试过这个:

<select class="form-control" th:field="*{parts}" multiple="multiple">
    <option th:each="part : ${partsAtribute}"
            th:field="*{parts}"
            th:value="${part.id}"
            th:text="${part.name}">Part name</option>
</select>
Run Code Online (Sandbox Code Playgroud)

不工作.我也试过这个:

<select class="form-control" th:field="*{{parts}}" multiple="multiple">
    <option th:each="part : ${partsAtribute}"
            th:field="*{parts}"
            th:value="${part.id}"
            th:text="${part.name}">Part name</option>
</select>
Run Code Online (Sandbox Code Playgroud)

也没用.我试过th:field="*{parts}"从选项标签中删除,结果相同..

如果我改变th:value${part}它的工作原理,但随后它并没有发回的ID字符串如[2,4,5,6,...],但Part像实例[第@ 43b45j,部分@ we43y7,...] ... .

更新:我刚刚注意到,如果只选择了一个部分,这是有效的:

<select class="form-control" th:field="*{parts}" multiple="multiple">
    <option th:each="part : ${partsAtribute}"
            th:field="*{parts}"
            th:value="${part.id}"
            th:text="${part.name}">Part name</option>
</select>
Run Code Online (Sandbox Code Playgroud)

如果选择了多个部件,则不起作用......

edit selected option thymeleaf

15
推荐指数
2
解决办法
3万
查看次数

Thymeleaf的Spring Security简单示例

嗨,我正在尝试按照一个简单的例子来做一个我在这个页面中找到的简单登录表单页面 http://docs.spring.io/autorepo/docs/spring-security/4.0.x/guides/form.html

问题是我每次尝试登录时都会收到此错误我收到此错误: Expected CSRF token not found. Has your session expired?

当我收到此错误时,我按下浏览器中的后退按钮并尝试第二次登录,当我这样做时,我收到此错误: HTTP 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'

在教程页面中是这条消息: We use Thymeleaf to automatically add the CSRF token to our form. If we were not using Thymleaf or Spring MVCs taglib we could also manually add the CSRF token using <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

"所以因为我也在使用百里香,我没有把这个标签添加到我的页面"

我找到了另一个解决方案,它的工作原理,这个解决方案是将此添加到我的安全配置类.csrf().disable()这个解决方案有效,但我想这样做是为了禁用我的页面中的csrf保护,我不想禁用这种类型的保护.

这是我的security-config类:

@Configuration
@EnableWebSecurity
public class ConfigSecurity extends WebSecurityConfigurerAdapter {

    @Autowired …
Run Code Online (Sandbox Code Playgroud)

java security spring-mvc spring-security thymeleaf

15
推荐指数
2
解决办法
3万
查看次数

Thymeleaf:将参数添加到当前网址

我在

http://example.com/some/page?p1=11
Run Code Online (Sandbox Code Playgroud)

我想在当前网址中添加一个参数,而不必重新定义它:

http://example.com/some/page?p1=11&p2=32
Run Code Online (Sandbox Code Playgroud)

有类似的东西:

<a th:href="@{?(p2=32)}">Click here</a>
Run Code Online (Sandbox Code Playgroud)

但上面的代码返回http://example.com/some/page?&p2=32(删除p1参数).

我怎么能用Thymeleaf做到这一点

java spring-mvc url-parameters thymeleaf spring-boot

15
推荐指数
2
解决办法
1万
查看次数

如何在百里香叶中打印数组大小?

我正在使用Thymeleafspring mvc 4,但是当我想要打印列表大小时我遇到了问题

<tr th:each="u : ${users}" th:id="${u.username}" class="odd gradeX">
    <th></th>
    <td th:text="${u.username}"></td>
    <td th:text="${u.email}"></td>
    <td th:switch="${u.enabled}">
        <span th:case="true" class="badge badge-primary">Acitf</span>
        <span th:case="false" class="badge badge-danger">Désactivée</span>
        <span th:case="*" class="badge badge-dark">Inconnue</span>
    </td>
    <td th:switch="${u.roles}">
        <span th:case="ROLE_SUPER_ADMIN">Super ADmin</span>
        <span th:case="ROLE_MANGER">Manager</span>
        <span th:case="ROLE_SUPERVISEUR">Superviseur</span>
        <span th:case="ROLE_USER">User</span>
        <span th:case="*">Inconnue</span>

    </td>
    <td th:text="${#calendars.format(u.creationDate,'dd/MM/yyyy hh:mm')}"></td>
    <td th:text="${#calendars.format(u.lastLogin,'dd/MM/yyyy hh:mm')}"></td>
    **
    <td th:text="${u.engines}"></td>
    <td th:text="${u.subordonnes}"></td>
    **
    <td></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

问题出在这里th:text="${u.engines}</td>.engines是我的User实体中的ArrayList .我尝试过th:size,th:list但它没有用.

任何人都可以帮助我

编辑

这是我的User实体:

@OneToMany(mappedBy …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc thymeleaf

15
推荐指数
1
解决办法
3万
查看次数