我有一个实体TaskInfo,它连接两个实体Task和TaskDetail用于下拉列表。
但是当我尝试持久化TaskInfo实体时,我得到“org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported警告:不支持请求方法'POST'”错误。
当我从TaskInfo实体中删除连接的实体时,persist工作正常。
我尝试为已加入的实体使用CascadeType = DETACH,但它不起作用,我仍然收到错误。
你有什么不对的帮助我?
这是TaskInfo实体,我删除了setter / getters。
@Entity
@Table(name="TASKINFO")
public class TaskInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer taskInfoId;
@NotNull
@Column(name="TASKID", nullable=false)
private Integer taskId;
@NotNull
@Column(name="TASKDETAILID", nullable=false)
private Integer taskDetailId;
@ManyToOne(targetEntity=Task.class, fetch=FetchType.LAZY)
@JoinColumn(name="taskId", referencedColumnName="taskId")
@Cascade({CascadeType.DETACH})
private Task taskListDD;
@ManyToOne(targetEntity=TaskDetail.class, fetch=FetchType.LAZY)
@JoinColumn(name="taskDetailId", referencedColumnName="taskDetailId")
@Cascade({CascadeType.DETACH})
private TaskDetail taskDetailListDD;
}
控制器:
@RequestMapping(value = { "/newTaskInfo" }, method = RequestMethod.POST)
public String saveTaskInfo(@Valid TaskInfo taskInfo, BindingResult result, ModelMap model) {
if (result.hasErrors()) {
return "registrationTaskInfo";
}
taskInfoService.save(taskInfo);
//taskInfoDegreeService.save(taskInfoDegree);
model.addAttribute("success", "TaskInfo " + taskInfo.getTaskInfoId() + " registered successfully");
model.addAttribute("loggedinuser", getPrincipal());
return "registrationsuccess";
}
服务部分:
@Override
public void save(TaskInfo taskInfo)
{
dao.save(taskInfo);
}
DAO部分:
@Override
public void save(TaskInfo taskInfo)
{
persist(taskInfo);
}
JSP部分:
<div class="well lead">Task Info Registration Form</div>
<form:form method="POST" modelAttribute="taskInfo" class="form-horizontal">
<form:input type="hidden" path="taskInfoId" id="taskInfoId"/>
<form:input type="hidden" path="taskId" id="taskId"/>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="taskId">Task Id</label>
<div class="col-md-7">
<form:select class="form-control" id="selectTaskListDD" path='taskListDD'>
<option value="-1">-Select-</option>
<form:options items="${taskListDD}"/>
</form:select>
<div class="has-error">
<form:errors path="taskId" class="help-inline"/>
</div>
</div>
</div>
</div>
<script>
$("#selectTaskListDD").change(function(){
var taskId = $("#selectTaskListDD").val();
$.ajax({
type: 'GET',
url: "/SpringMVCHibernateWithSpringSecurityExample/taskDetailListDD/" + taskId,
success: function(data){
var slctTaskDetailDD=$('#selectTaskDetailDD'), option="";
slctTaskDetailDD.empty();
option = option + "<option value='-1'>-Select-</option>";
for(var i=0; i<data.length; i++){
option = option + "<option value='"+data[i].taskDetailId + "'>"+data[i].taskDetailName + "</option>";
}
slctTaskDetailDD.append(option);
},
error:function(){
alert("error");
}
});
document.getElementById("taskId").value = taskId;
});
</script>
<form:input type="hidden" path="taskDetailId" id="taskDetailId"/>
<div class="row">
<div class="form-group col-md-12">
<label class="col-md-3 control-lable" for="taskDetailId">Task Detail Id</label>
<div class="col-md-7">
<%-- <form:input type="integer" path="taskDetailId" id="taskDetailId" class="form-control input-sm"/> --%>
<form:select class="form-control" id="selectTaskDetailDD" path="taskDetailListDD">
<option value="-1">-Select-</option>
</form:select>
<div class="has-error">
<form:errors path="taskDetailId" class="help-inline"/>
</div>
</div>
</div>
</div>
<script>
$("#selectTaskDetailDD").change(function(){
var taskDetailId = $("#selectTaskDetailDD").val();
document.getElementById("taskDetailId").value = taskDetailId;
});
</script>
<div class="row">
<div class="form-actions floatRight">
<c:choose>
<c:when test="${edit}">
<input type="submit" value="Update" class="btn btn-primary btn-sm"/> or <a href="<c:url value='/listTaskInfo' />">Cancel</a>
</c:when>
<c:otherwise>
<input type="submit" value="Register" class="btn btn-primary btn-sm"/> or <a href="<c:url value='/listTaskInfo' />">Cancel</a>
</c:otherwise>
</c:choose>
</div>
</div>
</form:form>