在属性文件中使用Thymeleaf - UTF-8的Spring Boot CRUD应用程序,可以通过以下步骤实现:
spring.thymeleaf.encoding=UTF-8
这将确保Thymeleaf使用UTF-8编码解析属性文件。
${...}
来引用属性。例如,要引用属性文件中的welcome.message
属性,可以这样写:<h1 th:text="${welcome.message}">Welcome</h1>
这将在页面上显示属性文件中定义的相应属性的值。
@Controller
public class HomeController {
@GetMapping("/")
public String home(Model model) {
model.addAttribute("welcome", new WelcomeMessage("Hello, World!"));
return "home";
}
}
在这个例子中,控制器将一个名为"welcome"的对象添加到模型中,并将其传递给名为"home"的Thymeleaf模板。
public class WelcomeMessage {
private String message;
public WelcomeMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
这个实体类将被用作模型中的属性。
通过以上步骤,你可以在Spring Boot应用程序中使用Thymeleaf和属性文件来实现CRUD操作,并确保使用UTF-8编码处理属性文件中的内容。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云