Springboot入门案例开发步骤_最简SpringBoot程序所包含的基础文件

2022年6月5日 882点热度 0人点赞 0条评论

入门案例开发步骤

①:创建新模块,选择Spring初始化,并配置模块相关基础信息
②:选择当前模块需要使用的技术集
③:开发控制器类

<code class="language-java">@RestController
@RequestMapping(&quot;/books&quot;)
public class BookController {
    @GetMapping(&quot;/{id}&quot;)
    public String getById(@PathVariable Integer id) {
        System.out.println(&quot;id ==&gt; &quot; + id);
        return &quot;hello , spring boot! &quot;;
    }
}</code>

④:运行自动生成的Application类

最简SpringBoot程序所包含的基础文件

<code class="language-xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.5.0&lt;/version&gt;
    &lt;/parent&gt;
    &lt;groupId&gt;com.shell&lt;/groupId&gt;
    &lt;artifactId&gt;springboot-01-quickstart&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/project&gt;
</code>
<code class="language-java">@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}</code>

注意事项:

基于idea开发SpringBoot程序需要确保联网且能够加载到程序框架结构

小小调酒师

此刻打盹,你将做梦; 此刻学习,你将圆梦。 个人邮箱:shellways@foxmail.com

文章评论