且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

REST API插件 - 使用body而不是查询字符串作为参数

更新时间:2023-11-07 21:10:22

我猜邮递员正在请求正文中发送JSON并设置内容类型 application / json 。如果你将 json 拦截器添加到堆栈,Struts可以解析请求。

I guess that postman is sending JSON in the body of the request and sets the content type application/json. Struts can parse the request if you add json interceptor to the stack.

<interceptor-stack name="myStack">
    <interceptor-ref name="json"/>
    <interceptor-ref name="myInterceptor"/>
    <interceptor-ref name="defaultStack"/>
</interceptor-stack>

json拦截器的描述 JSON插件

如果使用拦截器,将从请求中的JSON内容填充操作,这些是拦截器的规则:

If the interceptor is used, the action will be populated from the JSON content in the request, these are the rules of the interceptor:


  • content-type必须是application / json

  • JSON内容必须格式正确,请参阅 json.org 用于语法。

  • 对于必须填充的字段,操作必须具有公共setter方法。

  • 支持的填充类型有:Primitives(int,long ... String),Date,List,Map,Primitive Arrays,Other class(稍后会详细介绍)和其他数组class。

  • JSON中要填充在列表或地图中的任何对象都是Map类型(从属性映射到值),任何整数都是l类型为Long,任何十进制数字的类型为Double,任何类型为List的数组。

  • The "content-type" must be "application/json"
  • The JSON content must be well formed, see json.org for grammar.
  • Action must have a public "setter" method for fields that must be populated.
  • Supported types for population are: Primitives (int,long...String), Date, List, Map, Primitive Arrays, Other class (more on this later), and Array of Other class.
  • Any object in JSON, that is to be populated inside a list, or a map, will be of type Map (mapping from properties to values), any whole number will be of type Long, any decimal number will be of type Double, and any array of type List.

资源:

  • FAQ
  • Getting started
  • The resources page