第一種狀況java
webservice端代碼web
@Path("/DoSearch") public class DoSearchWebService { @Context UriInfo uriInfo; @Context Request request; @Context HttpServletRequest re; @POST @Produces( { MediaType.APPLICATION_JSON }) public BooksList getBooksList( @FormParam("SearchKey") String searchKey, @FormParam("UserId") String userId, @FormParam("PageNo") String pageNo, @FormParam("Count") String pageCount) { List<BooksListData> listData = new ArrayList<BooksListData>(); String resultCode = "0"; String resultMsg = ""; String resultCount = "0"; BooksList booksList = new BooksList(); try { listData =DaoFactory.getMeetingTypeDaoImp().getBooksListByKey(searchKey,userId, pageNo, pageCount); resultCount=listData.size()+""; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); }
用火狐瀏覽器模擬POST請求時,設置以下json
headers裏面的設置以下:瀏覽器
header裏面的設置要和這裏對應app
@Produces( { MediaType.APPLICATION_JSON })
備註:第一種狀況是,參數一塊兒傳入(可是分紅單個),單個解析。
code
第二種狀況orm
webservice代碼對象
@Controller @RequestMapping("/DoSearch") public class AddCustomerInfoController { @Autowired private GetCustomerVagueInfoMapper getCustomerVagueInfoMapper; @SuppressWarnings("unchecked") @RequestMapping(method = RequestMethod.POST) public @ResponseBody Object getUpdateInfo(@RequestBody String addInfo, HttpServletRequest request,HttpServletResponse response)throws Exception { //1.接收添加信息 JSONObject getObject = JSONObject.fromObject(addInfo); //返回對象 JSONObject data = new JSONObject(); BasicsBean<JSONObject> returnBean = new BasicsBean<JSONObject>(); //傳參 HashMap<String, Object> map = new HashMap<String, Object>(); map.put("SearchKey", getObject.get("SearchKey")); map.put("UserId", getObject.get("UserId")); map.put("PageNo", getObject.get("PageNo")); map.put("Count", getObject.get("Count")); return returnBean; }
用火狐瀏覽器模擬POST請求時,設置以下字符串
備註:第二種狀況,參數總體傳輸,做爲一個字符串,這種形式是將body裏面的內容當成一個json對象傳輸,webservice這端用addInfo這個對象(字符串對象,它能夠轉成json格式的對象)來接收,而後轉成json格式對象來解析。get