欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring 错误There was an unexpected error (type=Internal Server Error, status=500)解决方法

程序员文章站 2022-03-03 17:23:24
...
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by lixiaofei on 2019/10/18.
 */
@Controller

public class HelloController {

    @GetMapping("/hello")
    public String hello(@RequestParam(name = "name") String name, Model model){
        model.addAttribute("name",name);
        return "hello";
    }
}

出现错误如下:

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

Sat Oct 19 01:52:14 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Circular view path [hello]: would dispatch back to the current handler URL [/hello] again. 
Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to 
default view name generation.)

解决方案是在@GetMapping下面加上一行@ResponseBody即可。

 

相关标签: Spring Java