thymeleaf-入门基础
发布日期:2021-10-16 12:05:12 浏览次数:11 分类:技术文章

本文共 1486 字,大约阅读时间需要 4 分钟。

Thymeleaf:springboot默认配置模板引擎之一,可完全替代JSP

Springboot中使用thymeleaf的常用配置(src/main/resources/application.properties)

#端口server.port=7080#编码spring.thymeleaf.encoding=UTF-8#html5标签校验,LEGACYHTML5需要搭配一个额外的库NekoHTML才可用spring.thymeleaf.mode=LEGACYHTML5#页面缓存spring.thymeleaf.cache=false

pom.xml

org.springframework.boot
spring-boot-starter-thymeleaf
net.sourceforge.nekohtml
nekohtml
1.9.15

常用标签

1、下文可以使用 th:*形式的标签

 

2、获取变量值${…}

3、选择变量表达式*{…}

Name: Sebastian.

4、链接表达式: @{…} / th:href / th:src

springboot默认路径 src/main/view/static

 

5、条件运算

LoginLogin

User is an administrator

User is a manager

User is some other thing

6、循环

ID NAME AGE
1 18

7、导包快捷键 alt+enter

8、注解
一、@Controller 标记一个类是Controller (SpringMVC Controller 对象)控制器类,然后使用@RequestMapping 和@RequestParam 等一些注解用以定义URL 请求和Controller 方法之间的映射,这样的Controller 就能被外界访问到,
使用@RequestMapping 注解的方法才是真正处理请求的处理器

二、@Autowired是做bean的注入时使用,需要导包

public class TestServiceImpl {    // 下面两种@Autowired只要使用一种即可    @Autowired    private UserDao userDao; // 用于字段上        @Autowired    public void setUserDao(UserDao userDao) { // 用于属性的方法上        this.userDao = userDao;    }}

三、@EnableRedisHttpSession Redis进行配置来管理会话的项目

四、@Configuration 配置spring并启动spring容器(应用上下文)

转载地址:https://blog.csdn.net/snow51/article/details/98501194 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:layui.element--前端 UI 框架
下一篇:Android-Studio 运行报错

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月18日 21时29分09秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章