Springboot学习笔记(一)

注意第一个Helloworld项目:浏览发送/hello请求,响应hello,SpringBoot 2

原始SSM:MVC麻烦

1.创建Maven工程

2.引入依赖

 <!--导入Springboot-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>

 <dependencies>
        <!--导入web场景启动器,因为要开发Web-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
 </dependencies>

3.创建主程序

package com.cxy.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * 主程序类:@SpringBootApplication---这是一个SpringBoot应用
 */
@SpringBootApplication
public class MainAppliaction {
    public static void main(String[] args){
        SpringApplication.run(MainAppliaction.class,args);
    }
}

4.编写业务

package com.cxy.boot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

//@ResponseBody
//@Controller
@RestController
public class HelloController {
    @ResponseBody
    @RequestMapping("/hello")//映射请求
    public String handle01(){
        return "Hello Spring boot2!";
    }
}

5.测试;运行main方法

6.简化配置:application.properties

7.简化部署:打成jar包,直接执行

<!--为了创建一个可执行的jar,
    我们需要添加spring-boot-maven-plugin致我们的pom.xml文件。-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

注意取消CMD的快速依赖

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值