Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms SpringMVC表单用法:单选按钮绑定数据(整个对象不只是一个值)_Forms_Jsp_Spring Mvc_Radio Button - Fatal编程技术网

Forms SpringMVC表单用法:单选按钮绑定数据(整个对象不只是一个值)

Forms SpringMVC表单用法:单选按钮绑定数据(整个对象不只是一个值),forms,jsp,spring-mvc,radio-button,Forms,Jsp,Spring Mvc,Radio Button,我在使用构造从JSP通过POST将数据发送到后端时遇到问题: <form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/> 我不知道如何查看发送的请求。当我使用下面的构造时,一切都很好,但我不想只绑定对象的一个值,而是绑定整个对象: <form:radiobuttons path="pvClCategory.clcaCategory" items="${cat

我在使用构造从JSP通过POST将数据发送到后端时遇到问题:

<form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/>
我不知道如何查看发送的请求。当我使用下面的构造时,一切都很好,但我不想只绑定对象的一个值,而是绑定整个对象:

<form:radiobuttons path="pvClCategory.clcaCategory" items="${categoryList}" itemValue="clcaCategory" itemLabel="clcaCategory"/>
将其绑定到违例项所需的My ClCategory实体类。pvClCategory字段:

@Entity
@Table(name="PV_CL_CATEGORIES")
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class ClCategory implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="CLCA_ID")
    private long clcaId;

    @Column(name="CLCA_CATEGORY")
    private String clcaCategory;

    @OneToMany(mappedBy="pvClCategory")
    private List<Violation> pvViolations;

    public ClCategory() {
    }

    public long getClcaId() {
        return this.clcaId;
    }

    public void setClcaId(long clcaId) {
        this.clcaId = clcaId;
    }

    public String getClcaCategory() {
        return this.clcaCategory;
    }

    public void setClcaCategory(String clcaCategory) {
        this.clcaCategory = clcaCategory;
    }

    public List<Violation> getPvViolations() {
        return this.pvViolations;
    }

    public void setPvViolations(List<Violation> pvViolations) {
        this.pvViolations = pvViolations;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (clcaId ^ (clcaId >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ClCategory other = (ClCategory) obj;
        if (clcaId != other.clcaId)
            return false;
        return true;
    }
}
@实体
@表(name=“PV\U CL\U类别”)
@缓存(用法=缓存并发策略。只读)
公共类ClCategory实现了可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
@列(name=“CLCA\u ID”)
私人长clcaId;
@列(name=“CLCA\U类别”)
私有字符串分类;
@OneToMany(mappedBy=“pvClCategory”)
私人名单;
公共类别(){
}
公共长getClcaId(){
返回此.clcaId;
}
公共无效设置clcaId(长clcaId){
this.clcaId=clcaId;
}
公共字符串getClcaCategory(){
返回此.clc类别;
}
公共无效集合类别(字符串类别){
this.clcaCategory=clcaCategory;
}
公共列表getPvViolations(){
返回此.pv文件;
}
public void setpvinflictions(列出pvinflictions){
this.pvinvolutions=pvinvolutions;
}
@凌驾
公共int hashCode(){
最终整数素数=31;
int结果=1;
结果=素数*结果+(int)(clcaId^(clcaId>>>32));
返回结果;
}
@凌驾
公共布尔等于(对象obj){
if(this==obj)
返回true;
if(obj==null)
返回false;
如果(getClass()!=obj.getClass())
返回false;
ClCategory other=(ClCategory)obj;
if(clcaId!=other.clcaId)
返回false;
返回true;
}
}
此违例类在commandName属性的我的表单中使用,如下所示(文件名:v.jsp):


申请
我的控制器:

@Controller
@RequestMapping("/viol")
public class ViolationController {

    @RequestMapping("edit/{violationId}")
    public String edit(@PathVariable("violationId") long id, Map<String, Object> map) {
        Violation violation = violationService.getViolation(id);

        map.put("violation",violation);
        map.put("categoryList", adminService.listCategories());

        return "v";
    } 
}
@控制器
@请求映射(“/viol”)
公共类违规控制员{
@RequestMapping(“编辑/{violationId}”)
公共字符串编辑(@PathVariable(“violationId”)长id,映射){
违规=违规服务。getViolation(id);
地图放置(“违反”,违反);
put(“categoryList”,adminService.listCategories());
返回“v”;
} 
}
正如我在构造表单:radiobuttons path=”“items=“中所理解的,路径是数据绑定的属性,因此项目中交付列表中的整个对象都应该绑定到它。我将类别的项目列表放入ClCategory类型的对象中。提交后出现错误

当我使用form:radiobuttons path=“pvClCategory.clcaCategory”items=“${categoryList}”itemValue=“clcaCategory”itemLabel=“clcaCategory”仅绑定项中对象的字符串值时(在这两种情况下,使用类型为ClCategory的相同对象列表)然后表单被正确提交,但我不想只绑定objecte的一个值,而是绑定整个object。你能帮我一下我做错了什么吗

@Entity
@Table(name="PV_CL_CATEGORIES")
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class ClCategory implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="CLCA_ID")
    private long clcaId;

    @Column(name="CLCA_CATEGORY")
    private String clcaCategory;

    @OneToMany(mappedBy="pvClCategory")
    private List<Violation> pvViolations;

    public ClCategory() {
    }

    public long getClcaId() {
        return this.clcaId;
    }

    public void setClcaId(long clcaId) {
        this.clcaId = clcaId;
    }

    public String getClcaCategory() {
        return this.clcaCategory;
    }

    public void setClcaCategory(String clcaCategory) {
        this.clcaCategory = clcaCategory;
    }

    public List<Violation> getPvViolations() {
        return this.pvViolations;
    }

    public void setPvViolations(List<Violation> pvViolations) {
        this.pvViolations = pvViolations;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (clcaId ^ (clcaId >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ClCategory other = (ClCategory) obj;
        if (clcaId != other.clcaId)
            return false;
        return true;
    }
}
<form:form action="../update" method="post" commandName="violation">
    <form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/>
    <!-- other fields -->
    <button type="submit" value="Apply Changes" class="button-default" >Apply</button>
</form:form>
@Controller
@RequestMapping("/viol")
public class ViolationController {

    @RequestMapping("edit/{violationId}")
    public String edit(@PathVariable("violationId") long id, Map<String, Object> map) {
        Violation violation = violationService.getViolation(id);

        map.put("violation",violation);
        map.put("categoryList", adminService.listCategories());

        return "v";
    } 
}