ajax请求数据&JSON字符串

参考:https://blog.csdn.net/qq_39268603/article/details/80003265

  • jsp发请求


  • 从后端得到JSON字符串数据

    • 方一:可以创建相应实体,list转为JSON对象

      List tutorList = showTutorsListService.getTutorsByDepart(depart);
      
      //将list转换成json对象
      JSONArray jsonArray = JSONArray.fromObject(tutorList);
      
      //发送数据
      resp.getWriter().write(jsonArray.toString());
    • 方二:没有相应实体,也可以直接将字符串拼成JSON数组字符串,像下面那样。

    • (下面是JSON数组字符串 拼接后的结果)

      [
      {"specialty":"软件工程","sex":false,"tutorNo":"20170000","degree":"博士","birth":"2020-06-18","password":"20170000","tutorName":"root","post":"博士","phone":"155","quota":4,"surplusQuota":3,"researchField":"人工智能","depart":"计算机科学与技术学院","email":"124"}
      ,{"specialty":"计算机","sex":false,"tutorNo":"20170001","degree":"博士","birth":"2020-06-20","password":"20170001","tutorName":"root2","post":"博士","phone":"155","quota":4,"surplusQuota":4,"researchField":"人工智能","depart":"计算机科学与技术学院","email":"124"}
      ]
    • 浏览器控制台显示

      ajax请求数据&JSON字符串_第1张图片


  • jsp中数据显示表格

    
        
    序列 导师所属院系 学科方向 导师姓名 剩余名额 查看导师信息 申请导师

你可能感兴趣的:(ajax请求数据&JSON字符串)