1.新建專案




2.寫controller

package xiaoliu.springboot04.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping("hello")
@ResponseBody
public String hello(){
return "這是搭建springBoot第二種方式";
}
}
3.運行

4.瀏覽器輸入localhost:8080/hello訪問專案

兩種搭建springBoot方式對比
第一種方式
需要我們自己加入pom依賴

自己寫啟動spring專案的類

第二種方式
不需要我們自己添加pom依賴,而且啟動spring的類也會自動生成,我們只需要定義controller即可

第二種方式相比第一種搭建springBoot方式更加簡單快捷
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/168179.html
標籤:其他
上一篇:springAOP秘書老總案例
