springboot

SpringBoot

微程序服务阶段

SSM框架:简化了我们的开发流程,配置较为复杂

war:tomcat运行

spring再简化:SpringBoot - jar:内嵌tomcat;微服务架构

springcloud

Springboot

1.是什么

2.配置如何编写yaml

. 自动装配原理:重要

3.集成web开发:业务核心

4.集成数据库Druid

5.分布式开发:Dubbo(RPC) + zookeeper

6.swagger : 接口文档

7.任务调度

8.SpringSecurity (shiro)登录验证(AOP横切进去相当于拦截器)

springcloud

1.微服务

2.spring cloud 入门

3.Restful

4.Eureka

5.Ribbon

6.Feign

7.HyStrix

8.Zuul路由网关

9.SpringCloud config: git

SpringBoot简介

微服务架构
为了解决企业级应用开发的复杂性而创建
约定大于配置

第一个springboot程序

1、创建一个新项目

2、选择spring initalizr , 可以看到默认就是去官网的快速构建工具那里实现

3、填写项目信息

4、选择初始化的组件(初学勾选 Web 即可)

5、填写项目路径

注意:删除不必要的信息

6、等待项目构建成功

springboot原理

自动配置

pom.xml: spring-boot-starter-parent

spring-boot-dependencies:核心在父工程中(父依赖) SpringBoot的版本控制中心;

其中它主要是依赖一个父项目,主要是管理项目的资源过滤及插件!

spring-boot-starter-xxx:就是springboot 的场景启动器

主方法:springApplication

SpringApplication.run分析

分析该方法主要分两部分,一部分是SpringApplication的实例化,二是run方法的执行;

这个类主要做了以下四件事情:

1、推断应用的类型是普通的项目还是Web项目

2、查找并加载所有可用初始化器 , 设置到initializers属性中

3、找出所有的应用程序监听器,设置到listeners属性中

4、推断并设置main方法的定义类,找到运行的主类

yaml

对象、Map(键值对)

#对象、Map格式k:     v1:    v2:

在下一行来写对象的属性和值得关系,注意缩进;比如:

student:    name: qinjiang    age: 3

行内写法

student: {name: qinjiang,age: 3}

数组( List、set )

用 - 值表示数组中的一个元素,比如:

pets: - cat - dog - pig

行内写法

pets: [cat,dog,pig]

修改SpringBoot的默认端口号

配置文件中添加,端口号的参数,就可以切换端口;

server:  port: 8082

yaml的用法

spring boot的多文档配置

自动配置原理

application.yml配置文件到底可以写什么—联系—spring.factories

springboot web 开发

jar:webapp

自动装配

springboot到底帮我们配置了什么?我们能不能进行修改或扩展

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

要解决的问题

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

Thymeleaf

属性 th:

1.th:text/utext

th:text:原样显示,不会解析文本中的html标签

th:utext:会解析文本中的html标签

在不重启应用的情况下,更新页面。

1)在Idea的这个发生变更的html文件上按下组合键Ctrl + Shift + F9

2.th:name/value

该属性可以获取标签动态的name属性值,及标签的默认value值。

3.th:inline

内联属性需要配合着[[${xxx}]]来使用。

4.th:if

该属性用于逻辑判断,类似于JSTL中的<c:if/>

5.th:switch/case

该属性用于多分支判断,类似于JSTL中的switch-case。

6.th:each

遍历数组List、Set、Map,类似于jstl中的<c:foreach/>

1)遍历List

​ 遍历数组、List、Set方式是相同的。

2)常用状态属性

​ index:显示当前遍历对象的索引号(从0开始计数)

​ count:显示当前遍历对象的序号(从1开始计数)

​ even/odd:显示当前遍历对象是否为偶数/奇数(从0开始计数),布尔值

​ first/last:显示当前遍历对象是否是第一个/最后一个,布尔值

3)遍历Map

​ 首先要清楚,Map的一个键-值对是一个Map.Entry对象。

内置对象

一、Servlet API对象

​ 获取到Servlet域对象。通过#request、#session、#servletContext可以获取Servlet中的HttpServletRequest、HttpSession、ServletContext(application域)对象。

二、表达式实用对象

  • #messages:获取外部信息。
  • #uris/#urls:URI/URL处理工具。
  • #conversions:类型转换工具。
  • #dates:日期处理工具。
  • #calendars:日历处理工具。
  • #numbers:数字处理工具。
  • #strings:字符串处理工具。
  • #objects:对象处理工具。
  • #booleans:布尔值处理工具。
  • #arrays:数组处理工具。
  • #lists:List处理工具。
  • #sets:Set处理工具。||\s
  • #maps:Map处理工具。
  • #aggregates:聚合处理工具,例如,对数组、集合进行求和、平均值等。
  • #ids:th:id属性处理工具。
public class ThymeleafController {
    @RequestMapping("/hello")
    public String htmlHandler(Model model){
        model.addAttribute("hello","hello thymeleaf");
        return "welcome";
    }
    @RequestMapping("/school")
    public String Handler(Model model){
        School school = new School("张三","aynu", 123);
        model.addAttribute("school",school);
        model.addAttribute("name",school.getName());
        model.addAttribute("address",school.getAddress());
        model.addAttribute("number",school.getNumber());

        model.addAttribute("hi","<h5>hi,</h5><h2>world</h2>");

        model.addAttribute("name","hello springboot");
        model.addAttribute("sex","male");
        model.addAttribute("age",9);

        School school1=new School("rjxy","ay",1);
        School school2=new School("msxy","xxq",2);
        List<School> schools =  new ArrayList<>();
        schools.add(school1);
        schools.add(school2);
        model.addAttribute("schools",schools);
        System.out.println(schools);
        Map<String ,School> schoolMap =new HashMap<>();
        schoolMap.put("school1",school1);
        schoolMap.put("school2",school2);
        System.out.println("schoolMap"+schoolMap);
        model.addAttribute("schoolMap",schoolMap);

        return "welcome";
    }
    @RequestMapping("/servlet")
    public String servletHandler(HttpServletRequest servletRequest , HttpSession session) {
        servletRequest.setAttribute("myrequest","reqvalue");
        session.setAttribute("mysession","sessionvalue");
        session.getServletContext().setAttribute("myapplication","applivalue");
        return "welcome2";
    }
    @RequestMapping("/utility")
    public String utilityHandler(Model model) {
       int[] num={1,2,3,4,5,6};
       model.addAttribute("now",new Date());
       model.addAttribute("id","2342333333344333");
       model.addAttribute("num",num);
        return "welcome3";
    }
<h3>欢迎</h3>
<p th:text="${hello}">p标签</p>
<div th:text="${hello}">div</div>
<span th:text="${hello}">span</span>
<hr>
<div th:object="${school}">
    <p>学生:<span th:text="*{name}"></span></p>
</div>

<hr>
<p th:text="${hi}"/>
<p th:utext="${hi}"/>
<hr>
<input type="text" th:name="${name}" th:value="${school.name}">
<hr>
<p th:inline="text">姓名;[[${school.name}]]</p>
<hr>
<p th:if="${sex}==male"></p>
<hr>
<div th:switch="${age/10}">
    <p th:case="0">儿童</p>
    <p th:case="1">少年</p>
</div>
<hr>
<p th:each ="school : ${schools}">
    <span th:text="${school.name}"/>
    <span th:text="${school.address}"/>
    <br>
    <span th:text="${schoolStat.index}"/>
</p>
<hr>
<p th:each ="entry : ${schoolMap}">
    <span th:text="${entry.key}"/>
    <span th:text="${entry.value}"/>
    <span th:text="${entry.value.name}"/>
    <span th:text="${entry.value.address}"/>
    <br>
    <span th:text="${entryStat.index}"/>
</p>
<span th:text ="${#request.getAttribute('myrequest')}"/>

<span th:text ="${#session.getAttribute('mysession')}"/>
<span th:text ="${#servletContext.getAttribute('myapplication')}"/>
<hr>
<span th:text ="${#request.getContextPath()}"/>
<span th:text ="${#request.getParameter('name')}"/>

<span th:text ="${#dates.format(now)}"/>
<span th:text ="${#strings.substring(id,3,6)}"/>
<span th:text ="${#aggregates.sum(num)}"/>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值