• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

一篇文章带你了解SpringBoot Web开发

springboot 搞代码 4年前 (2022-01-09) 27次浏览 已收录 0个评论
文章目录[隐藏]

SpringBoot Web开发

springbo本文来源gaodaima#com搞(代@码$网6ot到底帮我们配置了什么?我们能不能修改?能修改那些东西?能不能扩展?

  • xxxAutoConfiguration: 向容器中自动配置组件
  • xxxProperties:自动配置类,装配配置文件中自定义的一些内容

要解决的问题:

  • 导入静态资源
  • 首页
  • jsp, 模板引擎 Thymeleaf
  • 装配扩展SpringMVC
  • 增删改查
  • 拦截器
  • 国际化

静态资源

总结:

1、在springboot,我们可以使用以下方式处理静态资源

1、导入依赖

  <!--Thymeleaf-->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
        </dependency>

html写在template文件下里面

2、controller书写

package com.kuang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/*
* 这个跳转需要模板引擎的支持
* 在template目录下的所有页面,只能通过controller来跳转*/
@Controller
public class IndexController {
    @RequestMapping("/test")
    public String test(){
        return "test";
    }
}

源码分析

html中获取显示后台controller传来的数据

1、在html中引入标签

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>
<!--所有的html元素都可以被thymeleaf替换接管   th:元素名-->
<div th:text="${msg}"></div>
</body>
</html>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:一篇文章带你了解SpringBoot Web开发
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址