SpringBoot 入门(一)

本文提供了一套简单易懂的Spring Boot项目搭建流程,包括Maven项目的创建、依赖引入、编译配置、启动类编写、RESTful API示例及打包部署步骤。适合初学者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

虽然很菜,可还是想稍微给人指个路,如果你需要的话。
以下内容,仅适合超级大白菜。编译器建议使用Idea。
新建MAVEN项目
1- pom引入jar

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

2- 打包编译工具

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.revosith.demo.Application</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

3- 新建一个启动类

@SpringBootApplication //这个注解 就是核心了
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

4 - 来个测试类

@RestController
public class Hello {

    @RequestMapping(value= "/hello")
    @ResponseBody
    public String sayHello(@RequestParam("name")String name){
        return "Hello "+name;
    }
}

5- 启动 Application

6- 哦哦哦 忘记 来个配置了
在resources 下面 新建文件 application.yml
贴进去

server:
  context-path: /
  port: 8081

7 - 启动Application

8 - http://localhost:8081/hello?name=revosith

9 - github 地址
https://github.com/RevoSith/demo

10 - 不接受批评,批评我,我就
谢谢你!

11 - 好处: install 打个包, 控制台直接 java -jar 你的jar包.jar 就可以启动了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值