在弹簧MVC控制器中接收参数

时间:2013-05-15 12:14:50

标签: java spring parameters

    @RequestMapping(value = "/Fin_AddCheckBook", method = RequestMethod.POST)
public @ResponseBody
JsonResponse addCoaCategory(
        @RequestParam(value="checkbookNumber", required=true) String checkbookNumber,
        @RequestParam(value="checkbookName", required=true) String checkbookName,
        @RequestParam(value="startNumber", required=true) long startNumber,
        @RequestParam(value="bankId", required=true) long bankId,
        @RequestParam(value="currencyId", required=true) long currencyId,
        @RequestParam(value="noOfLeves", required=true) int noOfLeves,
        @RequestParam(value="alertAt", required=true) int alertAt,
        @RequestParam(value="isActive", required=true) int isActive, Map map, Model model) {

我有两张表格!我希望通过指定@RequestParam(value =“startNumber”,required = true)long startNumber来按名称接收第一个表元素; 的 地图中的第二个表格元素,即地图地图

如何在地图中接收名称和所有其他元素的参数?

1 个答案:

答案 0 :(得分:0)

Create your own objects : 

public class MyMap {
    private String myObject1; // dont forget that these names should be same as @RequestParam values

    private Integer myObject2;

    //setters and getters. they are must!!

}

public class MyMap2 {
    private String my1;

    private Integer my2;

    //setters and getters. they are must!!

}

现在将此对象作为控制器方法的参数。

@RequestMapping(value = "/Fin_AddCheckBook", method = RequestMethod.POST)
public @ResponseBody JsonResponse addCoaCategory(MyMap myMap, MyMap2 myMap2, BindingResult result) {
    if (!result.hasErrors()) {
        // work with myMap myMap2
    }
}