1.导包:只需要添加这个包就可以完成
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.controller类
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController
public class Control {
//页面跳转
@RequestMapping("/index")
public ModelAndView it(){
ModelAndView modelAndView = new ModelAndView("index.html");
return modelAndView;
}
//页面输出字符串
@RequestMapping("/login")
public String at(){
return "hello2";
}
}
3.前端页面
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>controller跳转测试</title>
</head>
<body>
<p>你好</p>
</body>
</html>