接口的调用与调用别人的接口
此接口调用与被调用,都是在springMVC框架下使用
参数以json格式传输。
别人调用我们的接口,与controller方法开发类似
@RequestMapping("/otherUseMe.do")
public void otherUseMe (HttpServletRequest request,HttpServletResponse response) throw IOException{
//基本设置
response.setContent("appliction/json;charset=utf-8");
//用来给对方传递参数
PrintWriter out = response.getWriter();
//系统错误,返回结果
Map<String,Object> exceptionMap = new HashMap<String,Object>();
exceptionMap.put("code","999");
//将错误代码转为json字符串
String exceptionStr = JSONObject.fromObject(excetionMap).toString();
//接收传来的参数
String name = request.getParameter("name");
String gender = request.getParameter("gender");
try{
boolean flag = "业务处理";
if(失败flag){
Map<String,Object> falseMap = new HashMap<String,Object