1 在《SpringMVC笔记1---基于SpringMVC的第一个程序》的基础上,对IndexController类进行修改,修改后的类内容如下:
package com.gm.springmvc_test.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class IndexController {
@RequestMapping("/index")
public String indexController() {
return "index";
}
}
实际上就是在类前面用@RequestMapping进行注解,此时indexController方法匹配的URL将变为/test/index
2 在浏览器中输入localhost:8080/test/index,将显示index字符串。