使用jackson注解返还json对象(字符串数组),配合ajax做异步显示

来源:互联网 发布:数据搜索平台 编辑:程序博客网 时间:2024/04/30 02:05
package web;


import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class ActionServlet{
@RequestMapping("/flight.do")
public String flight(){
return "flight";
}

@RequestMapping("getFlight.do")
@ResponseBody
public Object getFlight(HttpServletRequest req,HttpServletResponse res) throws UnsupportedEncodingException{

String flight = req.getParameter("flight");
System.out.println(flight);



if("CA1234".equals(flight)){

return new String[]{"头等舱", "2400","商务舱","1800"};
}else{
return new String[]{"头等舱", "2200","商务舱","1200"};
}
}

}
0 0
原创粉丝点击