Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 使用@Controller时出现白标签错误,尽管项目结构正确_Spring Boot - Fatal编程技术网

Spring boot 使用@Controller时出现白标签错误,尽管项目结构正确

Spring boot 使用@Controller时出现白标签错误,尽管项目结构正确,spring-boot,Spring Boot,我已经使用start.spring.io创建了项目,但是当我使用@Controller时,我得到了白标签错误,当我将其更改为@RestController时,我没有得到任何错误。为什么?可能您没有合适的内容类型,因此spring无法识别请求,一般来说,常规控制器也应该根据您的注释工作 你还没有公布控制器本身的代码,所以我们只能猜测 简而言之,如果要将响应序列化为HttpResponse,应执行以下操作: @Controller @RequestMapping("students&qu

我已经使用start.spring.io创建了项目,但是当我使用@Controller时,我得到了白标签错误,当我将其更改为@RestController时,我没有得到任何错误。为什么?

可能您没有合适的内容类型,因此spring无法识别请求,一般来说,常规控制器也应该根据您的注释工作

你还没有公布控制器本身的代码,所以我们只能猜测

简而言之,如果要将响应序列化为HttpResponse,应执行以下操作:


@Controller
@RequestMapping("students")
public class SampleStudentsController {

    @GetMapping("/{id}", produces = "application/json")
    public @ResponseBody Student getStudent(@PathVariable int id) {
        return .... 
    }
}
另外请注意,还有一个
@RestController
注释,该注释自动“包含”在用于REST交互的更“专用”版本的控制器
@RestController

也考虑阅读更多信息