SpringBoot创建项目入门案例

目录结构

在这里插入图片描述

一、创建SpringBoot项目

1.创建骨架名称

在这里插入图片描述

2.给项目命名

在这里插入图片描述

3.配置pom.xml文件

在这里插入图片描述
在这里插入图片描述

4.MySql的驱动包

在这里插入图片描述

5.自动生成的pom.xml文件

<?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.3.0.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.william</groupId><artifactId>keepmoving</artifactId><version>0.0.1-SNAPSHOT</version><name>keepmoving</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>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

二、写入demo

package com.william.keepmoving.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @author :lijunxuan* @date :Created in 2020/5/27  22:42* @description :* @version: 1.0*/
@RestController
public class HoldOnLife {@RequestMapping("/hello")public String hello(){return "hello";}}

三、启动项目

在这里插入图片描述

发起请求
http://localhost:8080/hello

响应的页面
在这里插入图片描述

四、Spring的自动配置

在这里插入图片描述

五、yml文件的使用

特殊的单词出现的问题

在这里插入图片描述
home 会输出本地的home
country 会输出国家的英文简称

yml的两种注入方式

在这里插入图片描述

1.实体类注入

创建实体类

1.加入注解
@Component
@ConfigurationProperties(prefix = “user”)
2.加入以上两个注解时需要在pom.xml文件中加入配置处理器依赖
不加配置处理器依赖会提示
在这里插入图片描述

        <!--配置处理器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>

3.user要和yml文件中的user相同,user实体类要加入对应的get(),set()方法
4.点击实体类中的图标会跳转到yml文件对应的字段
在这里插入图片描述

package com.william.keepmoving.domain;import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;import java.util.Arrays;/*** @author :lijunxuan* @date :Created in 2020/5/28  22:26* @description :* @version: 1.0*/
@Component
@ConfigurationProperties(prefix = "user")
public class User {private String city;private String country;private String[] home;private String time;private String ip;private String password;private String test;@Overridepublic String toString() {return "User{" +"city='" + city + '\'' +", country='" + country + '\'' +", home=" + Arrays.toString(home) +", time='" + time + '\'' +", ip='" + ip + '\'' +", password='" + password + '\'' +", test='" + test + '\'' +'}';}public String getCity() {return city;}public void setCity(String city) {this.city = city;}public String getCountry() {return country;}public void setCountry(String country) {this.country = country;}public String[] getHome() {return home;}public void setHome(String[] home) {this.home = home;}public String getTime() {return time;}public void setTime(String time) {this.time = time;}public String getIp() {return ip;}public void setIp(String ip) {this.ip = ip;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getTest() {return test;}public void setTest(String test) {this.test = test;}
}

在yml文件中加入特定值
在这里插入图片描述
测试类需要注入
在这里插入图片描述

2.注解注入

在yml文件中配置
在这里插入图片描述
只需要在测试类中加入注解@value配置就可以了
在这里插入图片描述

六、数组

yml文件

在这里插入图片描述

实体类

在这里插入图片描述

package com.william.keepmoving.domain;import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;import java.util.Arrays;/*** @author :lijunxuan* @date :Created in 2020/5/28  22:26* @description :* @version: 1.0*/
@Component
@ConfigurationProperties(prefix = "user")
public class User {private String city;private String country;private String[] home1;private String time;private String ip;private String password;private String test;@Overridepublic String toString() {return "User{" +"city='" + city + '\'' +", country='" + country + '\'' +", home1=" + Arrays.toString(home1) +", time='" + time + '\'' +", ip='" + ip + '\'' +", password='" + password + '\'' +", test='" + test + '\'' +'}';}public String getCity() {return city;}public void setCity(String city) {this.city = city;}public String getCountry() {return country;}public void setCountry(String country) {this.country = country;}public String[] getHome1() {return home1;}public void setHome1(String[] home1) {this.home1 = home1;}public String getTime() {return time;}public void setTime(String time) {this.time = time;}public String getIp() {return ip;}public void setIp(String ip) {this.ip = ip;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getTest() {return test;}public void setTest(String test) {this.test = test;}
}

执行后的效果

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/333021.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

apache spark_Apache Spark Job的剖析

apache sparkApache Spark是通用的大规模数据处理框架。 了解spark如何执行作业对于获取大部分作业非常重要。 关于Spark评估范式的简要介绍&#xff1a;Spark使用的是惰性评估范式&#xff0c;在该范式中&#xff0c;Spark应用程序在驱动程序调用“ Action”之前不会执行任何…

MySQL常用权限的解释

文章目录全局管理权限数据库/数据表/数据列权限特别的权限全局管理权限 FILE: 在MySQL服务器上读写文件。 PROCESS: 显示或杀死属于其它用户的服务线程。 RELOAD: 重载访问控制表&#xff0c;刷新日志等。 SHUTDOWN: 关闭MySQL服务。 数据库/数据表/数据列权限 ALTER: 修改已…

No identifier specified for entity没有为实体指定标识符

异常 ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userController’: Injection of resour…

aws jenkins_Jenkins在AWS上(第1部分)

aws jenkins这是我对PEAT UK播客的逐字记录&#xff1a; 你好&#xff0c;再一次到另一个热点。 我叫Peter Pilgrim。 我曾经是DevOps专家&#xff0c;欢迎观看另一集。 这是11 Jenkins n AWS的第一部分&#xff0c;我是一名平台工程师&#xff0c;并且是Java Champion。 在…

SELECT ... FOR UPDATE_手动加行级排他锁_行级写锁_行级独占锁

文章目录介绍加锁情况分析明确指定主键&#xff0c;并且数据真实存在&#xff0c;锁定行明确指定主键&#xff0c;但数据不存在&#xff0c;不加锁主键不明确&#xff0c;锁定整个表无主键&#xff0c;锁定整个表应用场景介绍 1.FOR UPDATE 加的锁是一种行级排他锁&#xff0c…

广义表

广义表(广义表也称为列表&#xff0c;是线性表的一种推广&#xff0c;也是数据元素的有序序列) 一、基础 1.如何设定链表结点?广义表中的数据元素可能为单元素(原子)或子表&#xff0c;由此需要两种结点:一种是表结点&#xff0c;用以表示广义表;一种是单元素结点&#xff0c;…

数据库各种锁详解

文章目录排他锁共享锁更新锁意向锁锁的粒度数据库自动加锁手动加锁各种锁之间的兼容问题排他锁 Exclusive Locks&#xff0c;英译&#xff1a;排他锁&#xff0c;简称 X 锁&#xff0c;又称为写锁或独占锁。排他锁分为表级排他锁和行级排他锁。 如果事务 T1 对数据行对象 A 加…

activiti dmn_新的DMN编辑器预览

activiti dmnWorkbench 7.13.0.Final于10月16日星期二发布&#xff0c;此版本带来了许多有趣的功能和重要的修复程序。 亮点之一是作为技术预览功能的新DMN编辑器&#xff0c;该功能仍在开发中&#xff0c;但您可以开始使用。 在本文中&#xff0c;您将学习如何启用DMN编辑器预…

MySQL的索引存储数据结构BTree和B+Tree的区别

文章目录BTree 原理示意图BTree 原理示意图BTree的树层级很少BTree 可以高效支持范围查找BTree 原理示意图 注&#xff1a;BTree 就是 B-Tree&#xff0c;实际上官方并没有 B-Tree 的说法。 BTree 原理示意图 BTree的树层级很少 BTree 的数据存在每个节点中&#xff0c;所以每…

jdk11 javafx_JDK 11上的JavaFX

jdk11 javafx在JFX第11版发布后&#xff0c;人们对JavaFX与JDK的解耦感到百感交集。 我们许多人认为现在是时候告别JavaFX并改用另一种GUI技术了&#xff0c;而另一些人对此情况感到高兴。 他们认为&#xff0c;将JavaFX与Oracle分离开来&#xff0c;并致力于将其作为开源社区驱…

配置Java环境变量

JAVA环境变量配置 一、新建系统变量 新建变量&#xff0c;找到安装目录新建一个JAVA_HOME,路径为bin目录的前一级目录。 可以安装多个JAVA版本&#xff0c;然后新建不同的JAVA_HOME名称&#xff0c;然后填写bin目录的前一级路径。 二、编辑环境变量 找到path,然后编辑%JAVA…

MySQL的存储引擎InnoDB,B+Tree数据结构索引的实现原理图(聚簇索引/聚集索引)

1.表数据文件本身就是按BTree组织的一个索引结构文件 2.InnoDB的BTree的索引数据结构中&#xff0c;表数据和索引数据合并在一起&#xff0c;即叶子节点包含了完整的数据记录&#xff0c;这样的索引叫聚簇索引。

idea 切换java11_Java 11就在这里,您准备好进行切换了吗?

idea 切换java11在应该将Java 9发行版“震撼我们的世界”一年之后&#xff0c;我们一直在等待的LTS版本终于出现了 我们知道&#xff0c;大多数开发人员&#xff0c;团队&#xff0c;公司等尚未通过Java 8进行更新。 即使去年发布了模块Java 9&#xff0c;随后在3月又发布了Ja…

编译Java源文件

编写 新建hello.java文件 注意类名要和文件名称相同&#xff0c;如果不相同会提示错误 public class hello{public static void main(String[] args) {System.out.println("HelloWorld");} }编译 javac hello.java 编译会生成相应的.class文件。 运行 java hell…

oracle jdk_两个Oracle JDK的故事

oracle jdk最近 &#xff0c;人们担心 Java开发人员现在会无意中使用错误的Oracle提供的JDK实现&#xff08;从JDK 11开始 &#xff09;&#xff0c; Oracle提供了开源OpenJDK的构建 &#xff0c;并且还主要基于OpenJDK源提供了商业JDK的构建。 下表比较并对比了Oracle提供的两…

安装MAVEN和找不到JAVA_HOME问题原因

一、MAVEN安装 1.将下载好的MAVEN解压 2.配置MAVEN环境变量 MAVEN_HOME3.3.9 配置path 3.配置本地仓库 打开settings.xml进行修改 在MAVEN下新建一个repository文件夹 4.配置阿里MAVEN仓库配置 每次去阿里云下载jar包 <mirror><id>AliMaven</id>&…

数据库中的二级索引_普通索引_辅助索引

普通索引、二级索引、辅助索引是同个东西。 假设有张表的字段为 name&#xff0c;这个字段添加普通索引&#xff08;也叫二级索引&#xff09;&#xff0c;其存储引擎为 InnoDB&#xff0c;那么这个 name 索引的结构图&#xff1a;

2018-12 jdk_JDK 12新闻(2018年9月13日)

2018-12 jdk由于计划于本月晚些时候&#xff08;2018年9月25日&#xff09;发布JDK 11的 一般可用性 &#xff0c;是时候开始更仔细地研究JDK 12了 。 在OpenJDK jdk-dev邮件列表上的标题为“ JDK 12的计划时间表 ”的消息中 &#xff0c; 马克赖因霍尔德 &#xff08; Mark R…

idea连接mysql数据库时连接显示错误caching_sha2_password

问题描述 Connection to paradigmlocalhost failed. Unable to load authentication plugin caching_sha2_password.问题原因 mysql8之前的版本使用的密码加密规则是mysql_native_password&#xff0c;但是在mysql8则是caching_sha2_password&#xff0c;所以需要修改密码加密…

MySQL联合索引原理_复合索引_组合索引_多列索引

文章目录联合索引原理示意图联合索引就是复合索引、组合索引、多列索引。联合索引原理示意图