(1).SpringBoot项目结构分析

新建项目结构如图所示:

2.SpringBoot项目结构及启动

CxdemoApplication  :启动类,只要调用main方法便可以启动项目。

src/main/java  :主要编写业务。如controller,service,pojo,utils等等

src/main/resources  :存放配置文件。如application.properties。

src/main/resources/static :存放静态文件。如js,css,img等等。

src/main/resources/templates:存放html。如index.html等等。

src/test/java :主要用于测试。

  

(2).启动项目

首先在src/main/java下创建一个controller包,然后创建BeginController类

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

@RestController
@RequestMapping("/begin")
 public class BeginController {

    @RequestMapping("/beginTest")
    public String beginTest() {

         return "helllo world!";

    }
 }

2.SpringBoot项目结构及启动

点击右上角绿色三角形进行运行。

然后浏览器输入http://localhost:8080/begin/beginTest

2.SpringBoot项目结构及启动

由此运行成功!

相关文章: