java后台调用前端js方法传值问题

java后台调用前端js方法传值问题

js代码

function detail(useOrg, typeCountList, lng, lat){
	console.log("useOrg" + useOrg);
	console.log("typeCountList" + typeCountList);
	console.log("lng" + lng);
	console.log("lat" + lat);
}

java测试代码

import lombok.Getter;
import lombok.Setter;
import com.alibaba.fastjson.JSON;
import org.zkoss.zk.ui.util.Clients;

public class Test {

	@Getter @Setter 
	private Student student;
	@Getter @Setter 
	private List<Student> studentList;
	@Getter @Setter 
	private Float cityLng;
	@Getter @Setter 
	private Float cityLat;

	public void do() {
		String studentStr  = JSON.toJSONString(student);
		String studentListStr = JSON.toJSONString(studentList);
		Clients.evalJavaScript( "detail(" + studentStr + "," + studentListStr + "," + lng + "," + lat + ")" );
	}

}

分析

  • @Getter/@Setter : 注解在参数上,给参数提供读写方法
  • 调用后台js方法有很多,传参时需要注意把所有非简单类型的参数转化为json字符串,否则编译会出问题

猜你喜欢

转载自blog.csdn.net/liuniandexiatian/article/details/89331680