• 1.SpringBoot基础入门之HelloWorld


    一:创建Maven工程

    二:添加依赖

    官网文档最为致命

    We need to start by creating a Maven pom.xml file. The pom.xml is the recipe that is used to build your project. Open your favorite text editor and add the following:

     ①要用到SpringBoot的功能,只需要引入父项目boot-starter-parent

    1. <parent>
    2. <groupId>org.springframework.bootgroupId>
    3. <artifactId>spring-boot-starter-parentartifactId>
    4. <version>2.7.5version>
    5. parent>

    ②想要开发web,只需要添加web的场景启动器

    想以往我们Spring,SpringMVC要导入一大推的东西,现在我们只需要添加一个依赖,spring-boot-starter-web,我们称之为web的场景启动器,也就是说我们想要开发web场景了,把这个依赖导进来即可

    1. <dependencies>
    2. <dependency>
    3. <groupId>org.springframework.bootgroupId>
    4. <artifactId>spring-boot-starter-webartifactId>
    5. dependency>
    6. dependencies>

    三:编写你的代码即可

    ①编写业务代码之前,需要有一个主程序将它引导SpringBoot的启动

    1. /**
    2. * 主程序类
    3. * @SpringBootApplication:这是一个SpringBoot应用
    4. */
    5. @SpringBootApplication
    6. public class MainApplication {
    7. public static void main(String[] args) {
    8. SpringApplication.run(MainApplication.class,args);
    9. }
    10. }

    ②编写我们的业务代码

    1. //@ResponseBody
    2. //@Controller
    3. @RestController
    4. public class HelloController {
    5. @RequestMapping("/hello")
    6. public String handle01() {
    7. return "Hello,Spring Boot 2!";
    8. }
    9. }

    ③测试

    直接运行main方法即可

    成功在页面中显示

     ④简化配置

    application.properties,所有的配置都可以写在这个里面

    我们以前想要改tomcat端口号,还要改打开tomcat配置文件等等一大堆,现在SpringBoot是来整合其他所有东西的一个总框架,所以SpringBoot为了简化期间,将我们未来所有的配置都可以抽取在一个配置文件里面,application.properties。可以修改tomcat,SpringMVC的一些设置,什么都可以改噢

    server.port=8888

     ⑤简化部署

    我们再也不需要在目标服务器来安装tomcat等一大堆,只需要给我们工程里面引入

    1. <build>
    2. <plugins>
    3. <plugin>
    4. <groupId>org.springframework.bootgroupId>
    5. <artifactId>spring-boot-maven-pluginartifactId>
    6. plugin>
    7. plugins>
    8. build>

    把项目打成jar包,直接在目标服务器执行即可。

    注意点:

    • 取消掉cmd的快速编辑模式
  • 相关阅读:
    虹科分享 | AR眼镜开启工业创新之旅!
    Redis面试题(2022)
    【R语言与统计】SEM结构方程、生物群落、多元统计分析、回归及混合效应模型、贝叶斯、极值统计学、meta分析、copula、分位数回归、文献计量学
    云存储空间的动态分配技术
    三万字盘点Spring/Boot的那些常用扩展点
    springmvc
    MySQL事务和索引
    数字孪生可视化开发技术(ThingJS)学习笔记.1
    c++ json 库的调用报错 “value, object or array expected“
    Vue3+TS版本Uniapp:项目前置操作
  • 原文地址:https://blog.csdn.net/m0_56379670/article/details/127799066