如何在javascript文件中访问Spring MVC模型对象?
2022-09-02 22:49:59
我正在使用春季3 MVC,我有以下课程。
外部系统将使用以下 URL 调用我的应用程序:
http://somehost/root/param1/param2/param3
我有一个弹簧MVC控制器方法如下:
public ModelAndView showPage(@PathVariable("param1") String paramOne, @PathVariable("param2") String paramTwo, @PathVariable("param3") String paramThree, HttpServletResponse response) {
SomeModel model = new SomeModel(paramOne, paramTwo, paramThree);
return new ModelAndView("SomeJsp", "model", model);
}
一些模型.java
public class SomeModel{
private String paramOne;
private String paramTwo;
private String paramThree;
//constructor
//setters and getters
}
SomeJsp.jsp
//In this Jsp i have a div with few elements. Div is not visible by default.
//This jsp has externalJavascript included.
//I enable div and set the data into div elements using jquery.
<script src="<c:url value="/resources/js/extjs.js" />" type="text/javascript"></script>
外部J.js
$(document).ready(function() {
//Here i need the model returned using ModelAndView
//I can get data from model and set into div elements.
});
在外部java脚本文件中,是否可以获取模型内容?如果可能的话,我该怎么做?
谢谢!