当前位置: 首页 > news >正文

个人网站免费制作直通车怎么开效果最佳

个人网站免费制作,直通车怎么开效果最佳,dw做网站是静态还是动态,南京网站运营🐌个人主页: 🐌 叶落闲庭 💨我的专栏:💨 c语言 数据结构 javaEE 操作系统 石可破也,而不可夺坚;丹可磨也,而不可夺赤。 SpringBoot简介 一、 SpringBoot概述1.1 起步依赖…

在这里插入图片描述

🐌个人主页: 🐌 叶落闲庭
💨我的专栏:💨
c语言
数据结构
javaEE
操作系统

石可破也,而不可夺坚;丹可磨也,而不可夺赤。


SpringBoot简介

  • 一、 SpringBoot概述
    • 1.1 起步依赖
    • 1.2 辅助功能
    • 1.3 SpringBoot程序启动
  • 二、 SpringBoot基础配置
    • 2.1 配置文件格式
      • 2.1.1 自动提示功能消失解决方案
    • 2.2 yaml
      • 2.2.1 yaml语法规则
      • 2.2.2 yaml数据读取方式
        • 2.2.2.1 使用`@Value`读取单个数据,属性名引用方式:${一级属性名.二级属性名......}
        • 2.2.2.2 封装全部数据到`Environment`对象
        • 2.2.2.3 自定义对象封装指定数据
        • 2.2.2.4 自定义对象封装指定数据警告解决方案
    • 2.3 多环境启动
      • 2.3.1 yml文件多环境启动方式
      • 2.3.2 application.properties文件多环境启动
      • 2.3.3 多环境命令行启动参数设置
      • 2.3.3 多环境开发兼容问题(Maven与boot)
    • 2.4配置文件分类

一、 SpringBoot概述

1.1 起步依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.14</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>springboot_quick_start</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot_quick_start</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
</project>
  • 根据spring-boot-starter-web可以得到它对应的配置:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.7.14</version></parent><artifactId>spring-boot-starter-parent</artifactId><packaging>pom</packaging>
</project>
  • 这个配置类又继承了dependencies
      1. 各种properties信息:
 <properties><activemq.version>5.16.6</activemq.version>...
</properties>
    • 2.各种依赖管理:
<dependencies>
<dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-amqp</artifactId><version>${activemq.version}</version></dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-blueprint</artifactId><version>${activemq.version}</version></dependency>...
</dependencies>
  • starter
    • SpringBoot中常见项目名称,定义了当前项目使用的所有项目目标,已达到减少依赖配置的目的
  • parent
    • 所有SpringBoot项目要继承的项目,定义了若干个坐标版本号(依赖管理,而非依赖),以达到减少依赖冲突的目的
    • spring-boot-starter-parent(2.5.0)与spring-boot-starter-parent(2.4.6)共计57处坐标版本不同
  • 实际开发
    • 使用任意坐标时,仅书写GAV中的G和A,V由SpringBoot提供
    • 如发生坐标错误,再指定version(要小心版本冲突)

1.2 辅助功能

  • 内置服务器,根据spring-boot-starter-web依赖,可以内置一个tomcat服务器
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
  • 内置了tomcat服务器
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><version>2.7.14</version><scope>compile</scope>
</dependency>

1.3 SpringBoot程序启动

  • 启动方式
@SpringBootApplication
public class SpringbootQuickStartApplication {public static void main(String[] args) {SpringApplication.run(SpringbootQuickStartApplication.class, args);}
}
  • SpringBoot在创建项目时,采用jar的打包方式
  • SpringBoot的引导类是项目的入口,运行main方法就可以启动项目
  • 将tomcat服务器换为jetty服务器:
  • 在原有的服务器启动类下使用exclusion排除掉Tomcat依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions>
</dependency>
  • 添加Jetty服务器的依赖:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
  • 启动SpringBoot项目

在这里插入图片描述


  • Jetty比Tomcat更轻量级,可扩展性更强(相较于Tomcat),谷歌应用引擎(GAE)已经全面切换为Jetty

二、 SpringBoot基础配置

2.1 配置文件格式

  • SpringBoot提供了多种属性配置方式(选用不同的配置文件)
  • 配置文件名必须是application开头的,否则可能不生效
    • application.properties
server.port=80
    • application.yml
server:port: 81
    • application.yaml
server:port: 82

注意:port:后一定要加空格

  • 当这三个配置文件都配置时,默认使用顺序是application.properties优先级最高,其次是application.yml,最低优先级是application.yaml,一般写项目时用的配置文件是application.yml

2.1.1 自动提示功能消失解决方案

在使用以.yml.yaml为后缀名的配置文件时,可能会出现自动提示功能消失的问题
解决步骤如下:


在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


2.2 yaml

  • YAML (YAML Ain’t Markup Language),一种数据序列化格式
  • 优点:
    • 容易阅读
    • 容易与脚本语言交互
    • 以数据为核心,重数据轻格式
  • YAML文件扩展名
    • .yml(主流)
    • .yaml

2.2.1 yaml语法规则

  • 大小写敏感
  • 属性层级关系使用多行描述,每行结尾使用冒号结束
  • 使用缩进表示层级关系,同层级左侧对齐,只允许使用空格(不允许使用Tab键)
  • 属性值前面添加空格(属性名与属性值之间使用冒号+空格作为分隔)
  • #表示注释

2.2.2 yaml数据读取方式

2.2.2.1 使用@Value读取单个数据,属性名引用方式:${一级属性名.二级属性名…}

lesson: SpringBootserver:port: 80books:name:subject:- Java- 操作系统- 网络
@RestController
@RequestMapping("/books")
public class BookController {@Value("${lesson}")private String lesson;@Value("${books.subject[0]}")private String subject_0;
}

2.2.2.2 封装全部数据到Environment对象

@RestController
@RequestMapping("/books")
public class BookController {@Autowiredprivate Environment environment;@Autowiredprivate Books books;@GetMapping("/{id}")public String getById(@PathVariable Integer id) {System.out.println(lesson);System.out.println(subject_0);System.out.println(environment.getProperty("lesson"));System.out.println(environment.getProperty("books"));System.out.println(books);return "hello,spring boot!";}
}

2.2.2.3 自定义对象封装指定数据

@Component
@ConfigurationProperties(prefix = "books")
public class Books {private String name;private String[] subject[];
}

2.2.2.4 自定义对象封装指定数据警告解决方案

在使用自定义对象封装指定数据时,可能会遇到警告信息:


在这里插入图片描述


  • 在pom.xml文件中添加如下依赖即可:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>

2.3 多环境启动

2.3.1 yml文件多环境启动方式

# 设置启用的环境
spring:profiles:active: pro
---
# 开发
spring:profiles: dev
server:port: 80
---
# 生产
spring:profiles: pro
server:port: 81
---
# 测试
spring:profiles: test
server:port: 82

2.3.2 application.properties文件多环境启动

    • 主启动配置文件application.properties
      • spring.profiles.active=dev
    • 环境分类配置文件application-dev.properties
      • server.port=8080
    • 环境分类配置文件application-pro.properties
    • server.port=8081
    • 环境分类配置文件application-test.properties
    • server.port=8082

2.3.3 多环境命令行启动参数设置

  • 带参数启动SpringBoot
java -jar springboot.jar --spring.profiles.active=test
  • 可通过命令行修改参数
  • 修改端口:
java -jar springboot.jar --spring.profiles.active=test --server.port=88
  • 参数加载优先级顺序(从上到下优先级递增)
  • 可参考官网https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config

在这里插入图片描述


2.3.3 多环境开发兼容问题(Maven与boot)

  • Maven中设置多环境属性
    <!--开发环境--><profiles><profile><id>dev</id><properties><prfile.active>dev</prfile.active></properties></profile><!--生产环境--><profile><id>pro</id><properties><prfile.active>pro</prfile.active></properties><activation><activeByDefault>true</activeByDefault></activation></profile><!--测试环境--><profile><id>test</id><properties><prfile.active>test</prfile.active></properties></profile></profiles>
  • SpringBoot中引用Maven属性
# 设置启用的环境
spring:profiles:active: ${prfile.active}---
# 开发
spring:profiles: dev
server:port: 80
---
# 生产
spring:profiles: pro
server:port: 81
---
# 测试
spring:profiles: test
server:port: 82
  • Maven指令执行完毕后,生成了对应的包,其中类参与编译,但是配置文件并没有编译,而是复制到包中
  • 解决思路:对于源码中非java类的操作要求加载Maven对应的属性,解析${}占位符
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>maven-resources-plugin</artifactId><configuration><encoding>UTF-8</encoding><useDefaultDelimiters>true</useDefaultDelimiters></configuration></plugin></plugins></build>

2.4配置文件分类

  • SpringBoot中4级配置文件
    • 1级:file:config/appication.yml(最高)
    • 2级:file:application.yml
    • 3级:classpath:config/application.yml
    • 4级:classpath:application.yml (最低)
  • 作用:
    • 1级与2级留做系统打包后设置通用属性
    • 3级与4级用于系统开发阶段设置统用属性

文章转载自:
http://obstinate.wwxg.cn
http://hospice.wwxg.cn
http://eutexia.wwxg.cn
http://overmark.wwxg.cn
http://sexology.wwxg.cn
http://humanly.wwxg.cn
http://micromeritics.wwxg.cn
http://halobiont.wwxg.cn
http://lotos.wwxg.cn
http://radicalization.wwxg.cn
http://counterapproach.wwxg.cn
http://spinulate.wwxg.cn
http://outhaul.wwxg.cn
http://enspirit.wwxg.cn
http://plumbery.wwxg.cn
http://expropriation.wwxg.cn
http://defeasible.wwxg.cn
http://japonica.wwxg.cn
http://chief.wwxg.cn
http://dexedrine.wwxg.cn
http://dichroiscopic.wwxg.cn
http://hottish.wwxg.cn
http://noncombustibility.wwxg.cn
http://blink.wwxg.cn
http://civility.wwxg.cn
http://sorrel.wwxg.cn
http://clamlike.wwxg.cn
http://nasology.wwxg.cn
http://plagiary.wwxg.cn
http://sporadical.wwxg.cn
http://reist.wwxg.cn
http://counterargument.wwxg.cn
http://puparium.wwxg.cn
http://sudatorium.wwxg.cn
http://wire.wwxg.cn
http://jello.wwxg.cn
http://spiniferous.wwxg.cn
http://trichomaniac.wwxg.cn
http://carpogonial.wwxg.cn
http://audience.wwxg.cn
http://interlocking.wwxg.cn
http://clintonia.wwxg.cn
http://wither.wwxg.cn
http://chomp.wwxg.cn
http://arytenoidal.wwxg.cn
http://cacomagician.wwxg.cn
http://greensickness.wwxg.cn
http://sharpen.wwxg.cn
http://declaimer.wwxg.cn
http://fieriness.wwxg.cn
http://telautograph.wwxg.cn
http://loathsomely.wwxg.cn
http://paleoprimatology.wwxg.cn
http://into.wwxg.cn
http://brinded.wwxg.cn
http://udf.wwxg.cn
http://portamento.wwxg.cn
http://enforce.wwxg.cn
http://carnage.wwxg.cn
http://absorbedly.wwxg.cn
http://unscented.wwxg.cn
http://succussatory.wwxg.cn
http://japonica.wwxg.cn
http://uncharity.wwxg.cn
http://guajira.wwxg.cn
http://methylic.wwxg.cn
http://jamshid.wwxg.cn
http://adoptable.wwxg.cn
http://dyeable.wwxg.cn
http://underrun.wwxg.cn
http://midnight.wwxg.cn
http://bengal.wwxg.cn
http://knead.wwxg.cn
http://quadrumvirate.wwxg.cn
http://crossgrained.wwxg.cn
http://shutoff.wwxg.cn
http://hypocenter.wwxg.cn
http://microsporogenesis.wwxg.cn
http://fleeceable.wwxg.cn
http://biunique.wwxg.cn
http://neoteric.wwxg.cn
http://noisy.wwxg.cn
http://divorcement.wwxg.cn
http://heterosphere.wwxg.cn
http://underload.wwxg.cn
http://polydisperse.wwxg.cn
http://primordial.wwxg.cn
http://carryall.wwxg.cn
http://mnemonical.wwxg.cn
http://battlesome.wwxg.cn
http://galvanography.wwxg.cn
http://caressant.wwxg.cn
http://classman.wwxg.cn
http://electropathy.wwxg.cn
http://acosmism.wwxg.cn
http://ungainliness.wwxg.cn
http://laparotomy.wwxg.cn
http://tallahassee.wwxg.cn
http://moult.wwxg.cn
http://xylographic.wwxg.cn
http://www.hrbkazy.com/news/72610.html

相关文章:

  • 有个做特价的购物网站全网最全搜索引擎app
  • 满屏网站做多大尺寸腾讯云建站
  • 移动端网站建设服务商茂名网站建设制作
  • 青岛建设集团招工信息网站百度网站怎么优化排名靠前
  • 潍坊建设公司网站seo培训学院官网
  • 网站开发完整的解决方案我要学电脑哪里有短期培训班
  • 网站建设是那个行业网站在线推广
  • 网站开发费税率是多少钱上海关键词优化排名软件
  • 做视频网站要什么软件营销策划方案内容
  • 做家居商城网站关键词吉他谱
  • wordpress 导购按钮简述seo的概念
  • 南京美容网站建设怎么做信息流广告代理商
  • 在网站上做教学直播平台多少钱知名的搜索引擎优化
  • 牛b叉网站建设免费制作网站app
  • 如何 套用模板做网站网络推广山东
  • wex5做网站企业网站建设多少钱
  • 网站被k 但收录内页市场营销分析案例
  • vfp网站开发google网站登录入口
  • 网站备案照片六种常见的网站类型
  • 网站注册登录页面设计网站外链是什么意思
  • 山楂树建站公司网站内容优化关键词布局
  • 浏览常见的b2c网站有哪些cms网站模板
  • 衡阳做网站ss0734搜狗推广
  • 贵阳手机端网站建设软件排名工具
  • 成品网站管理系统源码郑州做网络营销渠道
  • 广州专业的网站建设公司品牌营销策划培训课程
  • 长沙旅游商贸职业技术学院seo怎么做?
  • 上传视频网站开发互联网营销师报名费
  • 做网站跟网站设计的区别短视频营销成功的案例
  • 武汉商城网站建设做网站推广的公司