发送动态字段数

时间:2016-08-29 14:26:19

标签: java html angularjs jstl

我在服务器端创建jsp并插入字段(使用jstl):

<c:forEach items="${fields}" var="field">
    <p><c:out value="${field.name}" /></p>
    <p><input type="hidden" ng-model ="name" value = "${field.name}" /></p>
    <p><input type="text" ng-model ="value"/></p>
</c:forEach>

如何将数据提交到服务器,如JSON对象:

var array = [
    { name: $scope.name, value: $scope.value },
    { name: $scope.name, value: $scope.value },
    ..........................................
    { name: $scope.name, value: $scope.value }
];

我正在寻找最实用的解决方案。

1 个答案:

答案 0 :(得分:0)

只需使用弹簧形式,即可形成用户对象。

public class UserDto {
        private String[] name;
        private String[] value;

        public String[] getName() {
            return name;
        }

        public void setName(String[] name) {
            this.name = name;
        }

        public String[] getValue() {
            return value;
        }

        public void setValue(String[] value) {
            this.value = value;
        }
    }

收集数据的对象:

@RequestMapping(value = "/registration", method = RequestMethod.POST)
    public String registration (@ModelAttribute("user") UserDto dto){
        User user = new User();
        String[] values = dto.getValue();
        String[] names = dto.getName();
        ArrayList<FieldValue> fieldValues = new ArrayList<FieldValue>();
        for (int i = 0; i < names.length; i++){
            Field field = fieldDao.findByName(names[i]);
            FieldValue tmp = new FieldValue(values[i], field, user);
            fieldValues.add(tmp);
        }
        user.setFields(fieldValues);
        userDao.save(user);
        return "redirect:/fields";
    }

和控制器:

main.o:main.cpp:(.text+0x461): undefined reference to  `_imp__pthread_create'
main.o:main.cpp:(.text+0x4be): undefined reference to `_imp__pthread_join'