SpringBoot2核心技术与响应式编程学习笔记(二)

学习内容:基础入门HelloWorld

1.下载maven

2.修改maven-settings.xml文件

  • 修改镜像文件、仓库位置(自己设置和创建)

3.参考官方文档

  • Developing Your First Spring Boot Application

  • Creating the POM

4.创建一个项目maven用idea

  • setting for New Projects

  • Build, Execution,Peloyment

  • Build Tools

  • Maven查看配置

  • maven home directory(用自己的地址)

  • user usettings file(自己文件的位置)

  • 用自己的仓库位置

5.创建好后点击Enable Auto-Import,目的:使idea自动导入

6.在pom.xml文件中把父工程parent导入文件里面(固定写法)

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
<!--        <version>3.2.2</version>
-->
           <version>2.1.8.RELEASE</version>
    </parent>
  • 注意依赖包的版本不要过高,如果配置的版本过低会报错

7.在pom.xml文件中添加系统依赖来开发web场景

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  1. Writing the Code

    • 主程序类@SpringBootApplication 目的表明这是一个SpringBoot应用

  • SpringApplication.run(MainApplication.class,args);//固定写法

  • 新建包Contoller,新建文件HelloContoller

  • 标注一个注解@Contoller

  • @RequestMapping("/hello")用来映射hello请求

  • @ResponseBody表明返回的话以字符串方式写给浏览器

  • @ResponseBody写在类上代表这个类的每一个方法它的数据直接写给浏览器而不是跳转某一个画面

  • @RestController是 @ResponseBody@Controller的合体

  • @RestController
    public class HelloContoller {
    ​
        @RequestMapping("/hello")
        public String handle01(){
            return "Hello,Spring Boot 2!";
    ​
        }
    }

9.运行程序:只需要在主类中运行main方法

10.在浏览器访问localhost:8080/hello

11.简化配置

  • 在resources下新建application.properties文件

  • server.port=8888 目的修改服务器端口号

12.简化部署

在pom.xml文件中,添加jar包插件

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
  • 运用插件使用打包把SpringBoot应用中的clean、package打包

  • target右键点击show in exporler 在路径后输入cmd回车

  • 注意事项:

    • 取消cmd的快速编辑模式

    • 配置好网络,刷新

  • 19
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值