@ResponseBody注解加上就可以返回字符串了,不加的话默认的是返回对应的静态页面的地址

2021-05-10 12:52:14 浏览数 (1)

前端报错: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Apr 21 13:55:42 CST 2021 There was an unexpected error (type=Not Found, status=404). ’ 后端跳出: : Initializing Spring DispatcherServlet ‘dispatcherServlet’ : Initializing Servlet ‘dispatcherServlet’ : Completed initialization in 1 ms

代码语言:javascript复制
@Controller
//@ResponseBody  //在使用此注解之后不会再走试图处理器,而是直接将数据写入到输入流中,他的效果等同于通过response对象输出指定格式的数据。
public class Test {

    @RequestMapping(value = "/te")//produces = "text/html;charset=utf-8"
    public String te(){
        return "asd.html";  //直接返回对应的文件的地址
    }

}

0 人点赞