简体   繁体   English

我如何使用Spring MVC无效控制器方法?

[英]How do i use spring mvc void controller method?

I am reading spring framework reference. 我正在阅读Spring框架参考。 When i read here . 当我在这里阅读。 I found that spring mvc supports returning void types.And then i read some examples of using void .But these examples do not make me to understand when time to use void .Is there a better example of how to use it? 我发现spring mvc支持返回void类型。然后我阅读了一些使用void示例。但是这些示例使我无法理解何时使用void 。是否有更好的示例来使用它?

From the referenced document: 从引用的文档中:

"... if the method handles the response itself (by writing the response content directly, declaring an argument of type ServletResponse / HttpServletResponse for that purpose) or if the view name is supposed to be implicitly determined through a RequestToViewNameTranslator (not declaring a response argument in the handler method signature)" “ ...如果该方法自行处理响应(通过直接编写响应内容,为此声明一个ServletResponse / HttpServletResponse类型的参数),或者该视图名称应通过RequestToViewNameTranslator隐式确定(不声明响应)处理程序方法签名中的参数)”

There are two conditions listed. 列出了两个条件。

  1. If the method writes to the servletResponse directly. 如果该方法直接写入servletResponse。 In this case, there is nothing for spring to do; 在这种情况下,春天无事可做。 a return value of void tells spring "I got this" and it does nothing with the response. 返回值void告诉弹簧“我知道了”,并且它对响应没有任何作用。
  2. If the view name can be determined vai a RequestToViewNameTranslator . 如果可以通过RequestToViewNameTranslator确定视图名称。 In this situation, spring knows the view to return based on the request, so no return value is required. 在这种情况下,spring根据请求知道要返回的视图,因此不需要返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM