English 中文(简体)
曼 谷 我有多幅URLs地图,用于一项行动,改变一个ool子参数?
原标题:Can I have multiple URLs map to an Action, changing a boolean parameter?

我有一个春天(3.1)的控制者行动方法,如:

@RequestMapping(value="/{id}")
public String myAction(@PathVariable("id") long someId) { ... }

I want to introduce a boolean:

public String myAction(@PathVariable("id") long someId, boolean doBranch) { ... }

然而,我希望根据使用URL的方法确定大豆。 换言之,我希望

/foo/123 => myAction(123,false)
/debug/foo/123 => myAction(123,true)

我知道,我可以给索取说明添加多份缩略语,但我没有看到一种办法,使地图本身能够影响一个参数,但距离参数或课程的流逝(/foo/123?doBranch=true>)。

我能轻松地把春天扩大到这样做吗? 或者,那里已经有一些事情要做?

最佳回答

我知道,这是最棘手的办法,但:

@RequestMapping("/foo/{id}")
public String myActionA(@PathVariable("id") long someId) {
   return myAction(someId, true);
}
@RequestMapping("/debug/foo/{id}")
public String myActionB(@PathVariable("id") long someId) {
   return myAction(someId, false);
}

public String myAction(@PathVariable("id") long someId, boolean doBranch) { ... }

Simply map the URLs to 2 different methods that call a third method with either true or false.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签