struts2-rest-plugin与struts2-json-plugin有何不同

我正在尝试在Struts2中开发一个休息服务。为此,我们可以通过struts2-rest-plugin或struts2-json-plugin来实现,只是想了解struts2-rest-plugin的实现与struts2-json-plugin有何不同。以下是struts2-json-plugin的工作代码

struts.xml

<package name="default" extends="json-default">
    <action name="getEmployeeDetails" class="com.world.employee.GetEmployeeDetails">
            <interceptor-ref name="json"/> 
            <result type="json">
                <param name="excludeNullProperties">true</param>
                <param name="noCache">true</param>
            </result>
    </action>
</package>

GetEmployeeDetails.java

class Employee{
    String name;
    String department;
    String age;
    String branch;
}
public class  GetEmployeeDetails implements action {

   private String empID;
   private Employee emp; 

  @Override
  public String execute() throws Exception {
      emp=new Employee();
      emp.name="Alex";
      emp.department="Navy";
      emp.age="40";
      emp.branch="Atlanta";



    if(emp == null) {
      return action.ERROR;
    }
    return action.SUCCESS;
  } 

}

来自邮递员:

URL : http://localhsot:8080/SampleRestExample/getEmployeeDetails
Body : 
{
              "empID":"5468",}
zgyanfeng 回答:struts2-rest-plugin与struts2-json-plugin有何不同

JSON插件提供操作的JSON序列化:https://struts.apache.org/plugins/json/

REST插件执行RESTful映射(或多或少),错误处理,序列化等:https://struts.apache.org/plugins/rest/

阅读这些插件的文档可以对它们之间的差异有一个清晰的了解。

本文链接:https://www.f2er.com/3081304.html

大家都在问