接受安卓发送的数据。
json串
控制器接受数据流 json串。 数据类似 {"memberId":"2"}
/**
* /api/uploadcontacts
*/
@ResponseBody
@RequestMapping("/api/uploadcontacts")
public JSONObject uploadimage(HttpServletRequest request) throws Exception {
JSONObject result = new JSONObject();
StringBuffer sb = new StringBuffer();
InputStream is = request.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s = "";
while ((s = br.readLine()) != null) {
sb.append(s);
}
String result1 = sb.toString();
System.out.println(result1);
JSONObject obj = JSONObject.fromObject(result1);
System.out.println(obj.getString("phone"));
System.out.println(obj.getString("yaoqing"));
System.out.println(obj.getString("data"));
String person=obj.getString("phone");
String yaoqing=obj.getString("yaoqing");
JSONArray array = JSONArray.fromObject(obj.getString("data"));
System.out.println("联系人一共:"+array.size());
List<Contacts> contactsList = new ArrayList<Contacts>();
Contacts contacts = null;
for(int i=0;i<array.size();i++) {
JSONObject item = (JSONObject) array.get(i);
//System.out.println(item);
System.out.println(item.getString("name"));
System.out.println(item.getString("phone"));
contacts = new Contacts();
contacts.setPerson(person);
contacts.setYaoqing(yaoqing);
contacts.setCreateDateTime(new Date());
contacts.setPhone(item.getString("phone"));
contacts.setName(item.getString("name"));
contactsList.add(contacts);
}
contactsService.add_list(contactsList);
return result;
} @ResponseBody
@RequestMapping("/api/vue/user/login")
public JSONObject login(@RequestBody Admin admin)throws Exception {
JSONObject result = new JSONObject();
System.out.println(admin.getName());
return result;
} public JSONObject edit_pwd(@RequestBody Member member,HttpServletRequest request )throws Exception {
站长微信:xiaomao0055
站长QQ:14496453