使用向?qū)Э焖賱?chuàng)建SpringBoot項目

1、使用Spring Initialize向?qū)?chuàng)建項目

2、創(chuàng)建成功后springboot相關(guān)的在pom.xml中配置已經(jīng)注入成功了

3、創(chuàng)建HelloController.java文件

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

// 這個類的所有方法返回的數(shù)據(jù)直接寫給瀏覽器,如果是對象轉(zhuǎn)為json數(shù)據(jù)
//@Controller
//@ResponseBody
@RestController  // 相當于 @Controller @ResponseBody
public class HelloController {
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!";
    }
}

4、resources下的目錄文件

  • static:保存所有的靜態(tài)資源:js、css、images
  • templates:保存所有的模板頁面;(SpringBoot默認jar包使用嵌入式的Tomcat,默認不支持JSP頁面);可以使用模板引擎(freemarker、thymeleaf)
  • application.properties:SpringBoot應(yīng)用的配置文件;可以修改一些默認設(shè)置,比如修改端口號將默認的端口號8080修改為8081
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容