使用Eclipse创建Springboot项目

使用Eclipse创建Springboot项目_第1张图片
使用Eclipse创建Springboot项目_第2张图片
使用Eclipse创建Springboot项目_第3张图片


    
        org.springframework.boot
        spring-boot-starter-web
    
    
          junit
          junit
          3.8.1
          test
    



    1.8



    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    

package com.how2java.springboot;

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

/**
 * @author 86182
 * @date: 2019年11月12日下午11:41:35
 * @verion:1.0
 * @description:创建 Application.java,
 * 其注解 @SpringBootApplication 表示这是一个SpringBoot应用,
 * 运行其主方法就会启动tomcat,默认端口是8080
 */
@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

创建HelloController

使用Eclipse创建Springboot项目_第4张图片

package com.how2java.springboot;

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

/**
 * @author 86182
 * @date: 2019年11月12日下午11:44:11
 * @verion:1.0
 * @description:
 * 控制器类HelloController, 这个类就是Spring MVC里的一个普通的控制器。
@RestController 是spring4里的新注解,是@ResponseBody和@Controller的缩写。
 */
@RestController
public class HelloController {
	
	@RequestMapping("/hello")
	public String hello(){
		return "Hello SpringBoot!";
	}
}

HelloController默认是和Application在同一包下
控制台输出:
使用Eclipse创建Springboot项目_第5张图片
运行结果
使用Eclipse创建Springboot项目_第6张图片

你可能感兴趣的:(java)