table: 【java|jsp页面ajax返回list(里面放有对象)进行循环并插入table】
ajax:
function searchSource(){ //获取搜索框里的值
var keyWord=$('#keyWord').val();
var typeSource = $('#typeSource option:selected').val();
//循环数据前先删除table的所有行
var tb = document.getElementById('datas');
var rowNum=tb.rows.length;
for (i=0; i
tb.deleteRow(i);
rowNum=rowNum-1;
i=i-1;
}
if( typeSource.length!=0 ){
$.ajax({
type: 'POST',
url: "${ctxFront}/media/PCfront/searchSource",
dataType: "json",
cache:true,
async:false,
data: {sourceName: keyWord,typeSource:typeSource},
success: function (data) {
if(data.result == 'success'){ //listSource为后台传过来的数组
var source=data.listSource;
for(i in source){
var tbBody = "";
tbBody += "
$("#datas").append(tbBody);
}
}else{
var tbBody = "";
tbBody += "
$("#datas").append(tbBody);
}
}
});
}
}
java后台: @ResponseBody
@RequestMapping(value = "https://www.it610.com/article/searchSource")
public void searchSource(HttpServletRequest request,HttpServletResponse response, Model model){
MemberInfo member = isLogin(request, response);
Map result = newHashMap();
Long typeSource = RequestUtil.getLong(request, "typeSource");
String sourceName = RequestUtil.getString(request, "sourceName");
System.out.println("sourceName:"+sourceName);
System.out.println("typeSource:"+typeSource);
result.put("result", "success");
result.put("message", "获取成功!");
if(member!=null && member.getId()>0){
if(typeSource==1){
MaterialVideo materialVideo=new MaterialVideo();
materialVideo.setMemberId(member.getId());
materialVideo.setName(sourceName);
List
System.out.println("listVideo:"+listVideo.size());
if(listVideo.size()>0){
result.put("result", "success");
result.put("listSource", listVideo);
result.put("message", "获取成功!");
}else{
result.put("result", "false");
result.put("message", "没有该素材");
}
}
if(typeSource==2){
MaterialAudio materialAudio=new MaterialAudio();
materialAudio.setMemberId(member.getId());
materialAudio.setName(sourceName);
List
System.out.println("listAudio:"+listAudio.size());
if(listAudio.size()>0){
result.put("result", "success");
result.put("listSource", listAudio);
result.put("message", "获取成功!");
}else{
result.put("result", "false");
result.put("message", "没有该素材");
}
}
}
writeJson(request, response, result);
}
推荐阅读
- Java|Java基础——数组
- 人工智能|干货!人体姿态估计与运动预测
- java简介|Java是什么(Java能用来干什么?)
- Java|规范的打印日志
- Linux|109 个实用 shell 脚本
- 程序员|【高级Java架构师系统学习】毕业一年萌新的Java大厂面经,最新整理
- Spring注解驱动第十讲--@Autowired使用
- SqlServer|sql server的UPDLOCK、HOLDLOCK试验
- jvm|【JVM】JVM08(java内存模型解析[JMM])
- 技术|为参加2021年蓝桥杯Java软件开发大学B组细心整理常见基础知识、搜索和常用算法解析例题(持续更新...)