用Eclipse+Maven快速創建一個SpringBoot項目


1. 去https://start.spring.io/默認下載一個maven項目 Generate Project(懂的話也可以更改其中的配置)。

2. 打開Eclipse,導入剛剛解壓的Maven項目。

3. 在demo下建立一個controller包,簡單顯示一點數據:

package com.example.demo.controller;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@RequestMapping("/springboot")
public class HelloController {
	@RequestMapping("/hello")
    public String hello() {
        return "Hello Spring Boot";
    }
}

  注意:maven包下還需要引入以下dependency:

<!-- 引入@RestController和@RequestMapping -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

  然后Java Application運行DemoApplication,瀏覽器輸入localhost:8080/springboot/hello即可看到

,這樣就搭建好了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM