我正在尝试将我的.js文件中的参数传递给控制器。
"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");
});
}
我需要将角色传递给下面的控制器代码。但是当我调试时,控制器中角色的值为null。当我没有通过角色以及通过上面的脚本传递角色时,下面的代码必须工作。
@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);
}
}
答案 0 :(得分:1)
您需要使用class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var imageArroy = [UIImage(named: "1"), UIImage(named: "2"), UIImage(named: "3"), UIImage(named: "5"), UIImage(named: "6")]
var imageArroyB = [UIImage(named: "a"), UIImage(named: "b"), UIImage(named: "c"), UIImage(named: "d"), UIImage(named: "e")]
var labelA: ["Electronics", "Cars", "Pets", "Mobiles", "Food"]
var labelB: ["UK", "Ireland", "India", "Germany", "Other EU"]
@IBOutlet weak var CollectionViewA: UICollectionView!
@IBOutlet weak var CollectionViewB: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
CollectionViewA.delegate = self
CollectionViewB.delegate = self
CollectionViewA.dataSource = self
CollectionViewB.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.CollectionViewA {
return 0 // Replace with count of your data for collectionViewA
}
return 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.CollectionViewA {
let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCellA", for: indexPath) as! CollectionCellA
// Set up cell
return cellA
}
else {
let cellB = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCellB", for: indexPath) as! CollectionCellB
// ...Set up cell
return cellB
}
}
注释方法参数role
,以告诉框架如何映射查询参数。
@RequestParam
由于您在网址中将其称为@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);
}
}
,因此您必须提供角色参数名称id
。否则,您可以重命名URL中的参数。