1. Open Idea to create a springboot web project:
2. The directory after the project is created:
3. Create a controller package at the same level as the program entry under demo, and create a OneController class under the package:
4. Write the code for the OneController class:
package com.springboot.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author Yang TanYing
* @Description:
* @create 2020-11-24 8:14
*/
@Controller//标明此类是控制层的
public class OneController {
@RequestMapping("/hello")//指定控制器可以处理名为("/hello")的URL请求
public String hello(){
//定一个hello()方法并返回"Hello World!"字符串
return "Hello World!";
}
}
5. Run the program, you can see that springboot comes with TomCat, the port number is: 8080: