SpringBoot学习

pom.xml配置

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.9.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

HelloWorldMain.class文件内容(主程序class)

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication		 //告诉springboot这是主程序
public class HelloWorldMain {

    public static void main(String[] args) {
    	//Spring应用启动起来(该class文件名为HelloWorldMain.class)  args为main传进来的参数名
        SpringApplication.run(HelloWorldMain.class,args);
    }
}

再页面输出HelloWorld

package com.hello;

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

import java.io.Writer;

@Controller
public class HelloWorld {
    @ResponseBody	//表示下面是返回正文
    @RequestMapping("/hello")	//表示浏览器路径是/hello
    public String hello(){
	return "HelloWorld!";		//表示返回正文是HelloWorld!
    }
}
package com.hello;

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

import java.io.Writer;
@RestController		//@ResponseBody 和@Controller的结合体
public class HelloWorld {
    @RequestMapping("/hello")	//表示浏览器路径是/hello
    public String hello(){
	return "HelloWorld!";		//表示返回正文是HelloWorld!
    }
}

效果展示
在这里插入图片描述

将springboot应用打包,可直接执行,不需要配置tomcat

<!--    将应用打包成可执行jar-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

使用方法:
在这里插入图片描述
在idea左下角点击此处,调出侧边栏
在这里插入图片描述
点击maven,再依次点击下面即可
在这里插入图片描述

打包后的jar位置
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值