一:SpringBoot是什么

springboot是对spring的缺点进行改善和优化,约定大于配置  开箱即用  没有代码生成 也无需xml 文件配置   可以修改属性值来满足需求

1) Spring Boot使编码变简单

2) Spring Boot使配置变简单

3) Spring Boot使部署变简单

4) Spring Boot使监控变简单

二:创建第一个SpringBoot工程

1、点击File--->New--->Project...

2、输入MAVEN,组名、包名等相关参数

3、选择SpringBoot版本,选择项目需要依赖的相关骨架包

注意:有些版本此处显示的是SpringWeb是一样的

4、设置项目保存目录:

5、项目创建完成,工程主界面如下:

删除多余的这三个文件

6、项目说明

(1)、默认有个Demo001Application类,里面是spring boot的载入函数

(2)、resource目录下有个application.properties文件,这个是Spring boot的配置文件

(3)、test目录下有个测试类Demo001ApplicationTests,这个是spring boot的单元测试

(4)、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.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.offcn</groupId>
<artifactId>firstdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>firstdemo</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-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
</project>

注意观察

一个继承spring-boot-starter-parent,两个依赖,spring-boot-starter-web web项目依赖必须,spring-boot-starter-test spring boot项目单元测试依赖

注意,很多人配置的maven远程仓库地址,其中很多配置的阿里云maven镜像,在这会有找不到最新Springboot相关包的问题,请把远程仓库指向华为云:

<mirror>

<id>huaweicloud</id>

<mirrorOf>*</mirrorOf>

<url>https://mirrors.huaweicloud.com/repository/maven/</url>

</mirror>

6、启动项目

找到如下文字,表明SpringBoot已经成功启动:

打开浏览器,输入地址:http://localhost:8080 ,出现如下画面

出现上图404错误是正常的,因为我们什么都没写。

7、编写HelloController

package com.offcn.demo.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.ResponseBody;

@Controller

public class HelloController {

@RequestMapping(value="/hello",method=RequestMethod.GET)

@ResponseBody

public String sayHello() {

return "hello spring Boot!";

}

}

注意HelloController所在包,必须在com.offcn.demo包,或者子包下面。

重启发现刚才写的hello已经映射出来了

访问http://localhost:8080/hello

最新文章

  1. 重拾smslib
  2. 【Selenium】1.介绍 Selenium
  3. javascript encodeURI和encodeURIComponent的比较
  4. jenkins集成自动化部署插件(一) deploy-plugin
  5. 实现Linux下的ls -l命令
  6. EventLog实现事件日志操作
  7. hello MemSQL 入门安装演示样例
  8. MySQL的索引创建、删除
  9. ios中XMPP的搭建
  10. 初次接触Linux
  11. Maven捆绑TestNG实现测试自动化执行、部署和调度
  12. (转载)sqlmap用户手册详解
  13. 五款实用免费的Python机器学习集成开发环境(5 free Python IDE for Machine Learning)(图文详解)
  14. iOS 几种加密方法
  15. java 两个日期之间的天数
  16. LINQ 查询
  17. 使用Maven创建Java项目
  18. Linux各主要发行版的包管理命令对照
  19. linux——Shell编程基础
  20. C#string数组转换到int数组并得到最大最小值

热门文章

  1. 关于@HtmlHelper帮助器参数
  2. 编译 datax
  3. Google开发者F12工具面板-network详解
  4. MySQL5.7增量备份恢复全实战
  5. php 使用fsockopen 发送http请求
  6. 不了解MES系统中的看板管理?看完本文就懂了
  7. 汇编指令之JMP,CALL,RET(修改EIP的值!!!)
  8. 动态改变伪元素样式的方(用:after和:before生成的元素)
  9. JOIN中的外连接(external join)
  10. centos7 yum 安装lnmp