以idea工具讲解
step1:创建一个springboot项目
idea中不像eclipse,没有项目的概念,这里创建一个module
step2
step3
step4.
目前我们只需要勾选上WEB依赖即可,后面依赖需要时一一添加
step5
step6
创建控制器
package com.hg.java.demo.business.test;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: hg
* @Date: 2018/12/10 11:52
* @Version 1.0
*/
@RestController
@RequestMapping("/testController")
public class TestController {
@GetMapping("/show/{name}")
public String show(@PathVariable String name){
return "hi, " +name +" , 你好!";
}
}
访问路径:http://localhost:8080/testController/show/zhangsan
注意:这样发布是没有项目名称的。若需要项目名称,在resource目录下,创建application.yml配置文件,添加以下配置
server:
servlet:
context-path: /demo
配置后访问路径:http://localhost:8080/demo/testController/show/zhangsan
step7
项目结构