Har*_*hal 5 java rest struts2 struts-action struts2-rest-plugin
我写了一个简单的代码来将rest与Struts 2.3.24集成
我有我的 Struts XML:
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.mapper.class" value="rest" />
<!-- Overwrite Convention -->
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="com.pag.rest.service"/>
<constant name="struts.convention.package.locators" value="service"/>
</struts>
Run Code Online (Sandbox Code Playgroud)
我的控制器类是:
package com.pag.rest.service;
public class RequestController {
// GET
public String index() {
return "SUCCESS";
}
// GET
public String show() {
return "SUCCESS";
}
// POST
public String create() {
return "Create - SUCCESS";
}
// PUT
public String update() {
return "SUCCESS";
}
// DELETE
public String destroy() {
return "SUCCESS";
}
}
Run Code Online (Sandbox Code Playgroud)
每当我尝试访问该服务时,它都会说未找到操作未映射异常。
请让我知道我还需要做什么才能使代码正常工作。
父包应该是rest-default. 将以下常量添加到配置文件中struts.xml:
<constant name="struts.convention.default.parent.package" value="rest-default"/>
Run Code Online (Sandbox Code Playgroud)
消除
<constant name="struts.convention.package.locators" value="service"/>
Run Code Online (Sandbox Code Playgroud)
并将您的包名称重命名为com.pag.rest.actions. 它将在actions文件夹下搜索您的控制器。
| 归档时间: |
|
| 查看次数: |
345 次 |
| 最近记录: |