开发环境
- IDEA2018.2.2
- tomcat7.0.94
- JDK1.8
- MySQL5.5.58
- Maven3.6.0
开发步骤
1.新建项目:打开IDEA,选择新建项目,左边列表选择Spring Initializr,点击Next:
2.填写Group包名、Artifact项目名,Packaging选择War,点击Next:
3.左侧选择Web后直接点击Next:
4.点击Finish:
5.项目新建完成打开后,点击右下角小弹窗中的Enable Auto-Import,开启自动导包:
6.编写相关代码:HelloController.java
package com.whut.controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class HelloController {
@RequestMapping("hello.do")
@ResponseBody
public String hello(){
return "hello springboot";
}
public static void main(String[] args){
SpringApplication.run(HelloController.class,args);
}
}
7.运行main()方法,控制台会输出“spring”的图形,然后在浏览器地址栏输入localhost:8080/hello.do,就会出现显示hello springboot的页面:
8.至此,“hello springboot”入门程序编写完成。