在thymeleaf中使用js获取后台传到前台的值

必须在html中做如下inline声明

	<script th:inline="javascript">
    var results = [[${detail}]];
	var _src = $(".numbers .number:first img").attr("src");
	if(_src) {
		var srcSplit = _src.split("-");
		refreshImg(".d_1_111_0", srcSplit[0]+"-"+(results["d_1_111_0"]||0)+"-"+srcSplit[2]);
	}
    function refreshImg(className, imgUri) {
		var img = $(className);
		if(img.attr("src") != imgUri) {
			img.attr("src", imgUri);
		}
	}
	</script>

且在普通js中已声明的方法需要再次声明

已标记关键词 清除标记
前台代码 ``` <form th:action="@{/loadredisstatus}" method="post" th:object="${redisbaseinfo}" > <select class="width-40 chosen-select" name="knowledgePointIdSet" data-placeholder="选择redis"> <option th:each="redisinfolist:${session.redisinfolist}" th:value="${redisinfolist.getRedisIp()}+':'+${redisinfolist.getRedisPort()}" th:text="${redisinfolist.getRedisIp()}+':'+${redisinfolist.getRedisPort()}" th:field="*{ipandport}" >模块名称</option> </select> <input type="submit" /> </form> ``` 后台代码 ``` @RequestMapping(value = "/loadredisstatus", method = RequestMethod.POST) public void loginPost(Model model, @ModelAttribute(value = "redisbaseinfo") RedisBaseInfo redisbaseinfo, HttpServletResponse response, HttpSession session) { String ipandport=redisbaseinfo.getIpandport(); System.out.println("in loadredisstatus "+ipandport); if(ipandport!=null&&!ipandport.trim().equals("")){ String [] arr=ipandport.split(":"); addCourse(response,session,arr[0],arr[1]); } } ``` RedisBaseInfo代码 ``` public class RedisBaseInfo extends BaseObject { private String ipandport; public String getIpandport() { return ipandport; } public void setIpandport(String ipandport) { this.ipandport = ipandport; } } ``` 如上所示现在 ``` th:object="${redisbaseinfo}" ``` 和 ``` th:field="*{ipandport}" ``` 两处报错,运行的话根本运行不起来,想实现的功能是选择一个下拉菜单选项并点击按钮提交后吧他的text封装到redisbaseinfo类里面传到后台处理,请问具体该怎么改这段代码呢
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__0809 返回首页