2016-04-08 108 views
0

我有一個Angular Client;其發佈數據到Java Rest Api。當我嘗試發送字符串或整數數據時,沒有任何問題。但是當我嘗試發送List時,它給出了一個類似的錯誤; enter image description hereRestfull Services org.netbeans.rest.application.config.ApplicationConfig引發異常

StandardWrapperValve [org.netbeans.rest.application.config.ApplicationConfig]:Servlet.service()進行的servlet org.netbeans.rest.application.config.ApplicationConfig拋出異常java.lang.IllegalArgumentException異常:參數類型錯配

和我的Java API

@POST 
@Path("/senddata") 
@Produces("application/json") 
public String sendData(List<Data> model) throws Exception { 
    System.out.println("model : " + model); 
return "OK"; 
} 

我的請求從Angularjs

return $http.post('http://localhost:8080/Project/webresources/json/product/senddata', postData1, { 
     headers: { 'Content-Type': 'application/json' } 
    }); 

我的字符編碼類

@WebFilter("*.xhtml") 
public class CharacterEncodingFilter implements Filter { 

    @Override 
    public void init(FilterConfig config) throws ServletException { 
    } 

    @Override 
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 
     request.getCharacterEncoding(); 
     response.getCharacterEncoding(); 
     request.setCharacterEncoding("UTF-8"); 
     response.setCharacterEncoding("UTF-8"); 
     response.setContentType("text/html; charset=UTF-8"); 
     chain.doFilter(request, response); 
    } 

    @Override 
    public void destroy() { 
    } 
} 

感謝

回答

0

你可以嘗試創建一個包裝對象爲您的列表和使用,在您的參數列表;或者將@RequestParam(value =「model」)註釋添加到現有參數中。

public String sendData(@RequestParam(value="model") List<Data> model) throws Exception 
+0

如果您使用如何實施建議的示例進行更新,您的答案會更有幫助。 –

+0

我同意@devlin –