1)、创建pages目录
2)、创建index.jsp文件
<%--
Created by IntelliJ IDEA.
User: andy
Date: 2023/10/14
Time: 20:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Index</title>
</head>
<body>
<h3>${msg}</h3>
</body>
</html>
package com.shenmazong.zg2.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
/**
* @author 军哥
* @version 1.0
* @description: 演示demo的controller
* @date 2023/10/14 17:02
*/
@Controller
@RequestMapping(value = "/index")
public class IndexController {
/***
* @description 测试接口
* @params
* @return java.lang.String
* @author 军哥
* @date 2023/10/14 17:48
*/
@GetMapping(value = "/hello")
@ResponseBody
public String hello() {
return "hello,world";
}
/***
* @description 使用Model展示数据
* @params model
* @return java.lang.String
* @author 军哥
* @date 2023/10/14 20:35
*/
@GetMapping(value = "/model")
public String model(Model model) {
model.addAttribute("msg", "hello,world!!!model!!!");
return "index";
}
/***
* @description 使用ModelAndView展示数据
* @params
* @return org.springframework.web.servlet.ModelAndView
* @author 军哥
* @date 2023/10/14 20:35
*/
@GetMapping(value = "/view")
public ModelAndView view() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("index");
modelAndView.addObject("msg", "测试ModelAndView");
return modelAndView;
}
}