第一种情况
webservice端代码
@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请求时,设置如下
headers里面的设置如下:
header里面的设置要和这里对应
@Produces( { MediaType.APPLICATION_JSON })
备注:第一种情况是,参数一起传入(但是分成单个),单个解析。
第二种情况
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格式对象来解析。
时间: 2024-10-10 07:10:08