java - Struts2 rest plugin how to create custom methods -
java - Struts2 rest plugin how to create custom methods -
my problem concerns creation of custom method within action. i'm using struts2 , restplugin in order implement rest webservice. action class following:
public class samplecontroller implements modeldriven<object> { private sample sample = new sample(); private collection<sample> list; private int id; public httpheaders create() { sdao.save(sample); homecoming new defaulthttpheaders("create"); } public httpheaders destroy() { homecoming new defaulthttpheaders("destroy"); } public httpheaders show() { homecoming new defaulthttpheaders("show").disablecaching(); } public httpheaders update() { sdao.save(sample); homecoming new defaulthttpheaders("update"); } public httpheaders index() { list = sdao.findall(); homecoming new defaulthttpheaders("index").disablecaching(); } public object getmodel() { homecoming (list != null ? list : sample); } public int getid() { homecoming id; } public void setid(integer id) { if (id != null) { this.sample = (sample) sdao.findbyid(id); } this.id = id; }
}
i can access resource via http method correctly. in order utilize custom method, called passing parameter search resources i.e
public searchbysendername(string sendername) { list.addall(sdao.findbysendername(sendername)) }
what right procedures? how can phone call via next url? give thanks much!
you can phone call custom method of predefined methods get
(index
, show
) in case, see restful url mapping logic . of course of study can alter method names used action mapper impact whole application. if occupied resource url should utilize perform job. in case if using strict rest
mapper. in mixed mode can map usual action action method. , don't specify method via !
or method:
prefix because it's restricted default configuration.
java rest struts2
Comments
Post a Comment