GVKun编程网logo

Spring MVC Controller:重定向,而没有将参数添加到我的网址中(springmvc 重定向带参数)

7

对于想了解SpringMVCController:重定向,而没有将参数添加到我的网址中的读者,本文将提供新的信息,我们将详细介绍springmvc重定向带参数,并且为您提供关于asp.net-core

对于想了解Spring MVC Controller:重定向,而没有将参数添加到我的网址中的读者,本文将提供新的信息,我们将详细介绍springmvc 重定向带参数,并且为您提供关于asp.net-core-mvc – 我是否需要在Visual Studio 2017 ASP.NET Core MVC中将Async添加到我的Controller Actions中、asp.net-mvc – 为什么ASP.Net MVC(或CodeIgniter)中没有内部Controller重定向?、java – Spring MVC中的@Controller注释和Controller类、Spring 3.0 MVC:无需将参数添加到我的网址即可进行重定向的有价值信息。

本文目录一览:

Spring MVC Controller:重定向,而没有将参数添加到我的网址中(springmvc 重定向带参数)

Spring MVC Controller:重定向,而没有将参数添加到我的网址中(springmvc 重定向带参数)

我正在尝试重定向,而没有将参数添加到我的URL中。

@Controller...public class SomeController{  ...  @RequestMapping("save/")  public String doSave(...)  {    ...    return "redirect:/success/";  }  @RequestMapping("success/")  public String doSuccess(...)  {    ...    return "success";  }

重定向后,我的网址始终看起来像这样:.../success/?param1=xxx&param2=xxx。由于我希望自己的URL是RESTful的,并且重定向后再也不需要参数,因此我不希望将其添加到重定向中。

有什么想法如何摆脱它们吗?

答案1

小编典典

在Spring
3.1中,使用选项ignoreDefaultModelOnRedirect禁用自动向重定向添加模型属性:

<mvc:annotation-driven ignoreDefaultModelOnRedirect="true" />

asp.net-core-mvc – 我是否需要在Visual Studio 2017 ASP.NET Core MVC中将Async添加到我的Controller Actions中

asp.net-core-mvc – 我是否需要在Visual Studio 2017 ASP.NET Core MVC中将Async添加到我的Controller Actions中

我刚刚将Visual Studio 2015 ASP.NET MVC Core项目转换为Visual Studio 2017 …我在错误列表中收到以下信息性消息

消息IDE1006命名规则违规:缺少后缀:’异步’

此消息出现在我的控制器中,重点关注以下内容:

public async Task<IActionResult> Index()

这也适用于创建,删除,详细信息和编辑.消息显示为信息,并适用于我的项目中超过1,000次出现.看来我需要将Index更改为IndexAsync
即.
    改变自:

public async Task<IActionResult> Index()
public async Task<IActionResult> Create()
public async Task<IActionResult> Delete(int? id)
public async Task<IActionResult> Details(int? id)

改成:

public async Task<IActionResult> IndexAsync()
public async Task<IActionResult> CreateAsync()
public async Task<IActionResult> DeleteAsync(int? id)
public async Task<IActionResult> DetailsAysnc(int? id)

这似乎是可选的,因为我的项目将构建并且它不是VS 2015中的问题.我不介意做这项工作,我需要确认在Visual Studio 2017 ASP.NET Core中更改它是正确的方法.

解决方法

微软正在推动你使用async这个词来为你的异步方法添加后缀.为什么? Visual Studio 2017的 release notes提到了这个花絮.

Task-like return types for async methods: This introduces the ability
to return any task-like type from an async method. PrevIoUsly these
return types were constrained to Task<T> and Task.

听起来不太明显哪些方法只是检查它们的返回类型是异步的.将它们与异步进行后缀可能是一个好主意.在VS提出这个“建议”之前,有一个previous stack overflow question辩论大会.来自微软的Stephen Toub对此发表了讲话.

If a public method is Task-returning and is asynchronous in nature (as
opposed to a method that is kNown to always execute synchronously to
completion but still returns a Task for some reason),it should have
an “Async” suffix. That’s the guideline. The primary goal here with
the naming is to make it very obvIoUs to a consumer of the
functionality that the method being invoked will likely not complete
all of its work synchronously; it of course also helps with the case
where functionality is exposed with both synchronous and asynchronous
methods such that you need a name difference to distinguish them. How
the method achieves its asynchronous implementation is immaterial to
the naming: whether async/await is used to garner the compiler’s help,
or whether types and methods from System.Threading.Tasks are used
directly (e.g. taskcompletionsource) doesn’t really matter,as that
doesn’t affect the method’s signature as far as a consumer of the
method is concerned.

Of course,there are always exceptions to a guideline. The most
notable one in the case of naming would be cases where an entire
type’s raison d’etre is to provide async-focused functionality,in
which case having Async on every method would be overkill,e.g. the
methods on Task itself that produce other Tasks.

As for void-returning asynchronous methods,it’s not desirable to have
those in public surface area,since the caller has no good way of
kNowing when the asynchronous work has completed. If you must expose a
void-returning asynchronous method publicly,though,you likely do
want to have a name that conveys that asynchronous work is being
initiated,and you Could use the “Async” suffix here if it made sense.
Given how rare this case should be,I’d argue it’s really a
case-by-case kind of decision.

I hope that helps,Steve

底线,这是信息性的.但是,随着Microsoft将返回类型扩展到Task以外,它开始变得越来越像最佳实践.用你自己的判断.

asp.net-mvc – 为什么ASP.Net MVC(或CodeIgniter)中没有内部Controller重定向?

asp.net-mvc – 为什么ASP.Net MVC(或CodeIgniter)中没有内部Controller重定向?

ASP.Net MVC控制器有几种将控制转发到另一个控制器或动作的方法.但是,所有这些都导致客户端重定向,具有302和新的浏览器请求.

为什么没有内部“调用另一个控制器的操作”功能,而不涉及客户端?我很确定PHP CodeIgniter框架也缺少这个功能.

我能提出的最好的理由是,最终它是不必要的,因为你想要调用的任何代码都可以被分解到某个常见的地方,至少在ASP.Net MVC中,操作可能非常昂贵.但是a lot of people ask about this,它似乎最终将是一种便利.

所以……很多聪明人设计了这些框架.没有这个必须有一些很好的理由吗?

解决方法

在Codeigniter中,您可以设置自定义路由和内容以将某些URL定向到其他控制器/操作,但我认为您的意思是在控制器功能的中间跳转到另一个?

如果您有任何业务逻辑,特别是如果它将被重用,它应该进入模型,而不是控制器.您还可以根据某些条件或某些内容在控制器中指定不同的视图.如果你有重复的代码不适合模型,那么它应该最终可以作为静态辅助函数,或者在库类中.

所以,是的,当你说:我认为你是对的

The best reason that I can come up with is that ultimately it’s unnecessary,since any code you want to call into Could be factored out into someplace common

这会迫使您保持在MVC模式中.

无论如何最好保持控制器的轻量级.

java – Spring MVC中的@Controller注释和Controller类

java – Spring MVC中的@Controller注释和Controller类

当我使用 Spring 3.x时
在使用注释时,我很难知道我们要使用这个@Controller获取哪种类型的Controller类
参考

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/Controller.html

这些是实现Controller类

AbstractController
AbstractUrlViewController
MultiActionController
ParameterizableViewController
ServletForwardingController
ServletWrappingController
UrlFilenameViewController
AbstractWizardFormController
SimpleFormController

但是当我们在Spring MVC中使用@Controller注释时
程序如何知道我们的@Controller注释正在实现
任何这些控制器,请有人解释我

解决方法

我想你在这里忽略了这一点.在过去注册控制器的过程中,您的类必须已实现控制器接口并选择请求映射类型.有时您必须实现大量代码才能实现单个请求映射.

如今,当我们有注释时,模型已经改变了.我们可以为每个控制器类处理多个请求类型.因为在单个@Controller注释类中,我们可以处理许多请求映射.

Controller注释是一个专门的@Component,它告诉Spring它内部会找到@RequestMapping处理程序.这些处理程序可用于返回Json,HTML或上传文件.

现在,与同一模块连接的逻辑可以放在单个控制器类下,您可以更灵活地实现所需的功能.其次,@ Controller使我们能够显着减少代码量.

Spring 3.0 MVC:无需将参数添加到我的网址即可进行重定向

Spring 3.0 MVC:无需将参数添加到我的网址即可进行重定向

我试图重定向而没有将参数添加到我的网址中。我的意思是重定向后,我的网址看起来像这样:… / success /?param1 =xxx&param2= xxx。

这个问题与这个Spring MVCController完全相同:重定向而没有将参数添加到我的url中

响应就是我正在寻找ignoreDefaultModelOnRedirect。问题是我正在使用Spring3.0。我该如何解决这个spring版本?

关于Spring MVC Controller:重定向,而没有将参数添加到我的网址中springmvc 重定向带参数的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于asp.net-core-mvc – 我是否需要在Visual Studio 2017 ASP.NET Core MVC中将Async添加到我的Controller Actions中、asp.net-mvc – 为什么ASP.Net MVC(或CodeIgniter)中没有内部Controller重定向?、java – Spring MVC中的@Controller注释和Controller类、Spring 3.0 MVC:无需将参数添加到我的网址即可进行重定向的相关知识,请在本站寻找。

本文标签: