不implements WebMvcConfigurer进行配置的话,默认跳转resources/templates文件夹下面的默认以html结尾的页面
@RestController
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController
@RequestMapping
public class TestController {
@GetMapping("/aa")
public String aa(){
//因为@RestController这个注解自带@ResponseBody序列化注解,所以返回的是字符串"in"
//如何想返回页面,看下面的API
return "in";
}
@GetMapping("/bb")
public ModelAndView bb(){
//内部跳转
//重点是ModelAndView类
//在使用@RestController注解的情况下,
//需要使用ModelAndView类跳转resources/templates文件夹下面的默认以html结尾的页面
return new ModelAndView("in");
}
}
@Controller
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping
public class Test1Controller {
@GetMapping("/aaa")
@ResponseBody
public String aaa(){
//因为有@ResponseBody序列化注解,所以返回的是字符串"in"
return "in";
}
@GetMapping("/bbb")
public String bbb(){
//内部跳转到resources/templates文件夹下面的默认以html结尾的页面
return "in";
}
}