

创建Spring Boot应用,选中我们项目中需要的模块
项目创建完后,其基础配置就已经完成,我们只需要在配置文件(application.yml)中指定少量的配置就可以运行
业务代码编写
一、SpringBoot对静态资源的映射
<dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.4.1</version></dependency>
classpath:/META-INF/resources/webjars/
private static final String[] CLASSPATH_RESOURCE_LOCATIONS =new String[]{"classpath:/META-INF/resources/","classpath:/resources/","classpath:/static/","classpath:/public/"};

private Resource getIndexHtml(String location) {return this.resourceLoader.getResource(location + "index.html");}
SpringBoot推荐的Thymeleaf;
语法简单,功能强大;
1、引入thymeleaf;
1)引入thymeleaf
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId><version>3.0.9.RELEASE</version></dependency>
2、Thymeleaf使用
@ConfigurationProperties(prefix = "spring.thymeleaf")public class ThymeleafProperties {private static final Charset DEFAULT_ENCODING;public static final String DEFAULT_PREFIX = "classpath:/templates/";public static final String DEFAULT_SUFFIX = ".html";private boolean checkTemplate = true;private boolean checkTemplateLocation = true;private String prefix = "classpath:/templates/";private String suffix = ".html";private String mode = "HTML";private Charset encoding;
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!DOCTYPE html><html lang="en" xmlns:th="http://www.thymeleaf.org"><head><meta charset="UTF-8"><title>Title</title></head><body><h1>展示</h1>姓名:<span th:text="${name}"></span>口头语:<span th:text="${say}"></span></body></html>
3)controller层
@Controllerpublic class UserController {@RequestMapping(value = "user")public String UserContext(Map<String,String> user){user.put("name","黄晓明");user.put("say","我不要你觉得,我要我觉得");return "user";}}
结果展示:
url: http://localhost:8080/user

3、语法规则

如果读完觉得有收获的话,欢迎点【在看】,关注【程序员溪言】,及时获得精彩推送!!!回复口令”java”,获得大量学习视频资料!
扫描二维码
获取更多精彩
关注【程序员溪言】

点这里在看

文章转载自程序员溪言,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




