Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

java - Custom function with additional argument using Struts 2 REST plugin

Is there anyway to have additional arguments in the URL of a Struts2 REST plugin controller?

For example, I have:

public class PersonController() implements ModelDriven<Object> {

    private Integer id;
    ...

    public String comment() { ... };
    // Getter and Setter for id
}

which is successfully reached with

[domain]/person/{id}/comment

However, what I would like to be able to is have a URL like

[domain]/person/{id}/comment/{commentId}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It would be not REST style to have such URLs. Instead, you can use two URLs to access different resources.

 [domain]/person/{id}

 [domain]/comment/{commentId}

On the other hand if you mix convention and rest style mapping you can use namedVariable or regex pattern matcher to achieve what you would like to have.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...