脚本宝典收集整理的这篇文章主要介绍了Springboot Web开发——2021-12-20,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
jar: webapp!
自动装配
Springboot 到底帮我们配置了什么?我们能不能修改?能修改哪些东西?能不能扩展? * xxxAutoConfiguration.. 向容器中自动配置组件 * xxxProperties: 自动配置类,装配配置文件中自定义的一些内容
要解决的问题: * 导入静态资源 * 首页 * jsp,模板引擎Thymeleaf * 装配扩展SpringMVC * 增删改查 * 拦截器 * 国际化
可直接在resources下static目录中直接创建index.html文件作为首页 也可使用thymeleaf模板引擎如下调用
jsp就是一种模板引擎,可以从后端绑定数据(${hello}) Thymeleaf就是一种功能类似的模板引擎
只要需要使用thymeleaf,只需要导入对应的依赖就可以了!我 们将html放在我们的templates
(resources下)目录下即可!
所有的html元素都可以被 thymeleaf 替换接管: th:元素名
@Controller
public class testController{
@RequestMapping("/test")
public String test(Model model){
model.addAttribute("msg","hello,springboot");
return "test"; //返回配置默认的位置templates下的test.html文件
}
}
//resources 下 templates目录中的test.html
<div th:text="${msg}" />
//可访问 localhost:8080/test 得
//在html1文件中,有复用目标代码(可单独提取一个commen页面)侧边栏,为其加上th:fragment="名称",如下
<div th:fragment="sidebar">
...
</div>
//在另一html2文件中,对其进行复用,调用th:insert="波浪线{目录/html文件名::fragment名}"即可
<div th:insert="~{html1::sidebar}" />
//注:也可在调用时传参数并在跳转接收html3页面中进行接收判断
//html2
<div th:insert="~{html1::sidebar(active='hello')}" />
//html3
<div th:text="${active=='hello'?'你好':'再见'}" />
<div th:color="${active=='hello'?'red':'blue'}" />
以上是脚本宝典为你收集整理的Springboot Web开发——2021-12-20全部内容,希望文章能够帮你解决Springboot Web开发——2021-12-20所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。