我在 AccountsController
中用 4 种不同的方法处理了 4 种类型的请求:
/accounts
显示所有账户/accounts/new
新建账户页面/accounts/{accountId}/edit
编辑账户页面/accounts/{accountId}/delete
删除一个账户
(1)
没问题。我只是返回 DisplayAccounts.jsp
View 。
关于 (2)
和 (3)
,当我将用户从初始 View 带到 DisplayAccounts.jsp
时(一旦操作是成功),URL 仍然是旧的(分别为 /accounts/new
或 /accounts/{accountId}/edit
)
对于 (4)
,我没有一个 View 可以开始。这只是一个操作,失败时应返回 View EditAccount.jsp
,成功时应返回 DisplayAccounts.jsp
。同样,最终 URL 应分别为 /accounts/{accountId}/edit
或 /accounts
。
我该如何实现?
最佳答案
作为请求的结果,您使用转发到新的 url。
查看示例:Spring MVC, forward
关于java - Spring - 如何控制为 View 显示的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12492714/