Struts2 Restful Mapping configuration

余生长醉 提交于 2020-01-06 11:26:09

问题


I'm new in struts2, I tried to use Restful but I can't config.

I have 2 Controllers:

UsersController

@Namespace("/api")
public class UsersController extends ActionSupport implements ModelDriven<Object> {
}

ListController

@Namespace("/api/users/{user_id}")
public class ListController extends ActionSupport implements ModelDriven<Object> {
}

I would like to create API like this:

/api/users/ -> method UsersController.index

/api/users/{user_id} -> method UsersController.show

/api/users/{users_id}/list -> method ListController.index

/api/users/{users_id}/list/{list_id} -> method ListController.show

I tried config struts.properties

struts.devMode = true
struts.convention.action.suffix = Controller
struts.convention.action.mapAllMatches = true
struts.convention.default.parent.package = rest-default
struts.convention.package.locators = controller
struts.rest.defaultExtension = json
struts.action.extension = 
struts.mapper.alwaysSelectFullNamespace = false
struts.mapper.idParameterName = id
struts.patternMatcher = namedVariable
struts.mapper.class = org.apache.struts2.dispatcher.mapper.Restful2ActionMapper
struts.enable.SlashesInActionNames = true

It doesn't work like what I want.

Do you have any suggestion?

来源:https://stackoverflow.com/questions/17484179/struts2-restful-mapping-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!