eclipse(mars版)下創建入門springboot[超詳細]

springboot入門只需3步(eclipse)

1、eclipse創建maven項目

  • New----Other

  • maven----Maven Project----Next

  • 勾上Create----Next

  • Artifact--Group Id(自定義包名,比如,com.xcl)
  • Artifact--Artifact Id(自定義項目名,比如,day200628--springboot)
  • Parent Project--Group Id(固定,org.springframework.boot)
  • Parent Project--Artifact Id(固定,spring-boot-starter-parent)
  • Parent Project--Version(固定形式版本號,比如,1.5.10.RELEASE)
  • Finish

  • 完整結構(第一次加載的話需要等待下載相關的jar)

2、導入相關pom包

  • 修改java版本號+springboot啓動器(第一次加載的話需要等待下載相關的jar)
<!-- 修改java版本號 -->
<properties>
	<java.version>1.8</java.version>
</properties>

<!-- springboot啓動器 -->
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
</dependencies>

3、編寫代碼並執行

  • 新建兩個包+類,【com.xcl--SysApp.class】【com.xcl.controller--TestController.class】
  • SysApp.class--springboot啓動類,必備main方法,而且包需要在相對應的controller【mapper,service....】上一級
  • TestController.class--普通的controller類

  • SysApp.class內容
package com.xcl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//Springboot必備啓動類註解
@SpringBootApplication
public class SysApp {
	public static void main(String[] args) {
		//Springboot必備run方法
		SpringApplication.run(SysApp.class, args);
	}
}

 

  • TestController.class內容
package com.xcl.controller;

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

//@ResponseBody+@Controller
@RestController
public class TestController {
	//Get+@RequestMapping
	@GetMapping("/resdata")
	public String resdata(){
		return "這是我第一個sprngboot!";
	}
}
  •  在SysApp.class啓動類右鍵運行

  •  控制檯信息,沒錯誤提示

  • 在網站輸入,http://localhost:8080/resdata

PS:本項目springboot已自帶tomcat,端口8080,如需外置tomcat或者修改版本號之類的話,另行百度

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章