我正在尝试将参数从我的 .js 文件传递到 Controller 。
"fnCreatedRow" : function(nRow, aData, iDataIndex) {
$(nRow).attr("row-id", aData["channelRole"]);
$(nRow).hover(function(event) {
var row = $(event.target.parentNode);
row.addClass('row-selected');
}, function(event) {
var row = $(event.target.parentNode);
row.removeClass('row-selected');
});
$(nRow).click(function(event) {
var row = $(event.target.parentNode);
document.location.href = "role-service-search.json?id=" + row.attr("row-id");
});
}
我需要将 Angular 色传递给下面的 Controller 代码。但是当我调试时, Controller 中 Angular 色的值为空。当我不传递 Angular 色以及通过上面的脚本传递 Angular 色时,下面的代码必须工作。
@RequestMapping(value = "/role-service-search", method = RequestMethod.GET )
public void searchRoleService(@ModelAttribute("request") final PageableRoleServiceSearchRequest request, final String role,
final BindingResult result) {
if (request.getInput() == null) {
RoleServiceSearchRequest newReq= new RoleServiceSearchRequest();
if(role!=null)
{
newReq.setChannelRole(role);
}
request.setInput(newReq);
}
}
最佳答案
你需要用@RequestParam
注解方法参数role
来告诉框架如何映射查询参数。
@RequestMapping(value = "/role-service-search", method = RequestMethod.GET )
public void searchRoleService(
@ModelAttribute("request") final PageableRoleServiceSearchRequest request,
@RequestParam(name = "id", required = false) final String role,
final BindingResult result) {
if (request.getInput() == null) {
RoleServiceSearchRequest newReq= new RoleServiceSearchRequest();
if(role!=null)
{
newReq.setChannelRole(role);
}
request.setInput(newReq);
}
}
由于您在 URL 中将其称为 id
,因此您必须提供 Angular 色参数的名称作为 id
。否则,您可以重命名 URL 中的参数。
关于javascript - 将参数从 .js 文件传递到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50851630/