niyidusk 2016-10-11 07:26 采纳率: 50%
浏览 9904

java在controller层怎么返回json数据给前台

/**
*
* @param request
* @return
*/
@RequestMapping(value = "linkCity", method = RequestMethod.POST)

@ResponseBody

public String linkCity(HttpServletRequest request){

String msg="";
try {

String privnce=request.getParameter("privnce");
List> msgList=new ArrayList>();
//根据省份获取市
List cityList = areaService.selectCity(privnce);
if(cityList.size()>0){

for (int i = 0; i < cityList.size(); i++) {

Area area=cityList.get(i);

Map msgMap=new HashMap();

msgMap.put("mcyCity", area.getCityname());

msgList.add(msgMap);

}

}

} catch (Exception e) {

e.printStackTrace();

}
return ;
}

要return什么回去..求指教
  • 写回答

3条回答 默认 最新

  • 策码奔腾L 2016-10-11 07:26
    关注

    试试用jsonObject把msgList的数据转化一下,然后就能return了

    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗