1 IDEA创建一个项目
输入包名 项目名
选中Web Spring Web
2 打开HelloworldApplication!
package com.example.helloworld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloworldApplication {
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}
@SpringBootApplication声明为主程序
3编写Control类
package com.example.helloworld.control;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
@Controller
public class HelloControl
{
@ResponseBody
@RequestMapping("/hello")
public String hello(){
return "Hello World";
}
}
@Controller声明为Control类
4 启动主程序
访问服务器http://localhost:8080/hello
4 将项目导出为jar包
启动Mavenzhong中LifeCycle的package 会在target中生成jar包