天天看點

Thyemleafajax傳回json:前台ajax接收并指派模态框:點選事件傳值:

  1. gt:great than(大于)>
  2. ge:great equal(大于等于)>=
  3. eq:equal(等于)==
  4. lt:less than(小于)<
  5. le:less equal(小于等于)<=
  6. ne:not equal(不等于)!=

ajax傳回json:

@RequestMapping("/toUpdate")
	@ResponseBody
	public UserInfor toUpdate(String id, Model model) {
		UserInfor userInfor = userInforRepostitory.findById(id).get();
		model.addAttribute("user", userInfor);
		return userInfor;
	}
           

前台ajax接收并指派模态框:

<script type="text/javascript">
		function cz(id){
			/* alert(id); */
			/* console.log(id); */
			 $.ajax({
	            url: "/toUpdate",
	            data: "id="+id,
	            type: "post",
	            dataType:"json",
	            success: function (data) {
	            	console.log(data.id);
	            	$("#userName").val(data.userName);
	            }
	        });
		}
</script>
           

點選事件傳值:

原因

3.x版本的thymeleaf為了防止注入攻擊,更新了安全機制。

解決

修改前:

<button th:οnclick="'javascript:del(this,\''+${quartzInfo.id}+'\');'" type="button"></button>      

修改後:

<button th:data-id="${quartzInfo.id}" οnclick="del(this,this.getAttribute('data-id'))" type="button"></button>      

轉載于:https://my.oschina.net/u/3942108/blog/2993431

繼續閱讀