狂神说SpringBoot

狂神说SpringBoot

在这里插入图片描述

一、Spring

1.什么是Spring?

在这里插入图片描述

Spring是如何简化开发的

在这里插入图片描述

SpringBoot优点

在这里插入图片描述

在这里插入图片描述

2.第一个SpringBoot程序

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

然后next

在这里插入图片描述

选中web---->spring web------>next就可以了

创建完成之后编写一个 controller就可以执行了

3.彩蛋

在这里插入图片描述

就可以在这里看到

替换Spring

在这里插入图片描述

生成文字的网址:https://www.bootschool.net/ascii/

4.Springboot原理

自动装配

pom.xml

  • Spring-boot-dependencies : 核心依赖在父工程中!
  • 我们在或者引入一些Springboot依赖的时候, 不需要指定版本,就因为有这些版本仓库

启动器

  •   <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
    1234
    
  • 启动器:说白了就是Springboot的启动场景;

  • 比如Spring-boot-starter-web, 他就会帮我们自动导入web环境所有的依赖!

  • Springboot会将所有的功能场景, 都变成一个个的启动器

主程序

  •   //@SpringBootApplication : 标注这个类是一个Springboot的应用
      @SpringBootApplication
      public class Springboot01HellowordApplication {
          //将Springboot的应用启动
          public static void main(String[] args) {
              SpringApplication.run(Springboot01HellowordApplication.class, args);
          }
      
      }
    
  • 注解

  • 结论

  • 在这里插入图片描述

5.谈谈你对Springboot的理解?

  • 自动装配
  • run
    • 在这里插入图片描述

6.properties和yaml配置

properties k=v

yaml k= v //k=空格v

yaml

yaml基本语法

在这里插入图片描述

yaml 编写实体类信息

爆红

在这里插入图片描述

给实体类赋值

在这里插入图片描述

在这里插入图片描述

properties配置(第二种)

在这里插入图片描述

松散绑定

jsr303数据校验

在这里插入图片描述

在这里插入图片描述

源码位置

在这里插入图片描述

yaml多环境配置

在这里插入图片描述

7.自动装配原理

在这里插入图片描述

可以通过debug=true查看那些自动配置类生效

在这里插入图片描述

二.SpringBoot web 开发

在这里插入图片描述

在这里插入图片描述

1.静态资源

  • 在springboot,我们可以使用一下方式处理静态资源
    • webjars localhost:8080/webjars/
    • public , static , /** , resources localhost:8080/
  • 优先级 : resources > static > public

在这里插入图片描述

2.首页如何配置

首页

在这里插入图片描述

图标

关闭默认图标

在这里插入图片描述

在public文件下 导入 favicon.ico命名的图片文件

在这里插入图片描述

在这里插入图片描述

3.Thymeleaf语法

取值和for-each循环

th:元素名=" "

controller

在这里插入图片描述

test.html (templates下的)

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

thymeleaf依赖
<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
---------------------------------------------------------------
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

controller

@Controller
public class testController {

    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("msg","hello1 springboot");
        model.addAttribute("users", Arrays.asList("于海峧","codeyuaiiao","123456"));
        return "test";
    }
}

test.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <div th:text="${msg}"></div>

        <div th:each="user:${users}" th:text="${user}"></div>
    </body>
</html>

4.视图解析器

在这里插入图片描述

5.springmvc拓展

在这里插入图片描述

在这里插入图片描述

6.项目

  1. 首页配置:
    1. 注意点,所有页面的静态资源都需要使用thymeleaf接管;
    2. url: @{}
  2. 页面国际化:
    1. 我们需要配置i18n文件
    2. 我们如果需要在项目中进行按钮自动切换,我们需要自定义一个组件localeResolver
    3. 记得将自己写的组件配置到适配spring容器 @Bean
    4. #{}
  3. 登录+拦截器
    1. 提取公共页面
      1. th:fragment="sidebar"
      2. th:replace="~{commons/commons::topbar}"
  4. 增删改查

7.前端

  • 模板: 别人写好的 我们拿来改成自己的用
  • 框架: 组件: 自己动手组合拼接 ! Bootstrap(12) , Layui(12),semantic-ui(16)
    • 栅格系统
    • 导航栏
    • 侧边栏
    • 表单

8.如何做一个网站

  1. 前端搞定: 页面长什么样子 ;数据
  2. 设计数据库 (数据库设计难点!)
  3. 前端让他能够自动运行, 独立化工程
  4. 数据局接口如何对接 : json ,对象 all in one!
  5. 前后端联调测试 !
  • 有一套自己熟悉的后台模板 : 工作必要! x-admin
  • 前端界面 :至少自己能够通过前端框架 ,组合出来一个网站页面
    • index
    • about
    • blog
    • post
    • user
  • 让这个网站能够独立运行

在这里插入图片描述

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值