小编Pau*_*uhn的帖子

Spring MVC使用form:checkbox来绑定数据

我知道围绕这个主题已有问题,但我还没弄清楚如何解决以下问题:

我有一个用户/角色关系,我想列出JSP中的所有可用角色作为复选框项,其中选中了用户分配的复选框.但是,不检查匹配的项目(这里我使用的是Spring 3.1).

从User对象中提取:

private Set<RoleEntity> roles = new HashSet<RoleEntity>();
Run Code Online (Sandbox Code Playgroud)

从Spring Controller中提取(将用户对象和角色列表添加到Model):

UserEntity userEntity = userEntityService.findById(UserEntity.class, new Long(id));
model.addAttribute("userAttribute", userEntity);

List<RoleEntity> roleList = roleEntityService.findAll();
model.addAttribute("roleList", roleList);
Run Code Online (Sandbox Code Playgroud)

从JSP中提取:

<form:form modelAttribute="userAttribute" method="POST" action="${saveUrl}">
...

    <table align="center">
        <tr>
            <td>ID</td>
            <td>Role Name</td>
        </tr>
        <c:forEach items="${roleList}" var="role" varStatus="status">
            <tr>
                <td><form:checkbox path="roles" value="${role}" label="${role.id}" /></td>
                <td><c:out value="${role.name}" /></td>
            </tr>
        </c:forEach>
    </table>

...
</form:form>
Run Code Online (Sandbox Code Playgroud)

Spring MVC文档说明了这一点:当绑定值是array或java.util.Collection类型时,如果绑定的Collection中存在已配置的setValue(Object)值,则输入(复选框)将标记为"checked".

这不是这个案子吗?我在这里错过了什么?

非常感谢.

保罗

spring spring-mvc

13
推荐指数
1
解决办法
5万
查看次数

Spring-Data-JPA使用XML配置在Spring STS中导致XSD验证错误

Eclipse/STS使用Spring 3.2.1与Spring-data-jpa一起报告错误.我有一些带有以下标头的XML配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
Run Code Online (Sandbox Code Playgroud)

我使用Spring 3.2.1和Spring-Data-JPA 1.3.0,Eclipse/STS报告这个:

引用文件包含错误(http://www.springframework.org/schema/data/jpa)

这发生在包含data-jpa架构的每个XML配置文件中.当我从XML配置中删除JPA时,一切都很好.

我的配置错了或这里发生了什么?

谢谢!保罗

spring spring-data-jpa

3
推荐指数
1
解决办法
2462
查看次数

标签 统计

spring ×2

spring-data-jpa ×1

spring-mvc ×1