Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在springboot中使用Thymeleaf将值传递给HTML模板的变量_Java_Spring Boot_Thymeleaf_Sendgrid - Fatal编程技术网

Java 如何在springboot中使用Thymeleaf将值传递给HTML模板的变量

Java 如何在springboot中使用Thymeleaf将值传递给HTML模板的变量,java,spring-boot,thymeleaf,sendgrid,Java,Spring Boot,Thymeleaf,Sendgrid,我正在设置发送电子邮件的API。我正在使用Thymeleaf的模板引擎来格式化电子邮件的正文 我无法将值传递给HTML文件中的变量 我尝试过使用setVariable函数 Context Context=newcontext(); //setVariable(“html中的变量”,“它的值”);//像这样 setVariable(“name”、“ajay”); setVariable(“日期”、“23rdfeb”); 环境变量(“卢比”,399); 字符串sendDay1Email=templa

我正在设置发送电子邮件的API。我正在使用Thymeleaf的模板引擎来格式化电子邮件的正文

我无法将值传递给HTML文件中的变量

我尝试过使用
setVariable
函数

Context Context=newcontext();
//setVariable(“html中的变量”,“它的值”);//像这样
setVariable(“name”、“ajay”);
setVariable(“日期”、“23rdfeb”);
环境变量(“卢比”,399);
字符串sendDay1Email=templateEngine.process(“lifecyclemailer/sample”,上下文);
omemessage.get().setText(sendDay1Email,true);
电子邮件模板:

Dear `${name}`, your pack will expire on `${date}` of `${rupee}`.
Dear Ajay, your pack will expire on 23rd Feb of 2019.
Dear [[${name}]], your pack will be expired on [[${date}]] of [[${rupee}]].
这是我应该收到的电子邮件

电子邮件模板:

Dear `${name}`, your pack will expire on `${date}` of `${rupee}`.
Dear Ajay, your pack will expire on 23rd Feb of 2019.
Dear [[${name}]], your pack will be expired on [[${date}]] of [[${rupee}]].

这是我所期待的电子邮件。

一般来说,Thymeleaf表达式仅在HTML标记属性(如
)或内联表达式(如
[[${name}]]]
中处理。您的模板可能需要如下所示:

电子邮件模板:

Dear `${name}`, your pack will expire on `${date}` of `${rupee}`.
Dear Ajay, your pack will expire on 23rd Feb of 2019.
Dear [[${name}]], your pack will be expired on [[${date}]] of [[${rupee}]].

(这受模板引擎配置方式的影响,但我认为内联表达式可以在所有模式下工作。)

删除“$name”并替换为“name”已尝试过此方法,但无效。