例如,我有这样的gsp代码,这是表标记内容:
<table class="table">
<thead>
<tr>
<th>Restaurant name</th>
<th>Booking date</th>
<th>Booking time from</th>
<th>Booking time till</th>
<th>Hall</th>
<th>Place in table</th>
<%-- <th>Price</th>--%>
<th></th>
</tr>
</thead>
<tbody>
<g:each in="${tableInfo}" var="table">
<tr>
<td>${table.cafeeName.cafeeName}</td>
<td>${new SimpleDateFormat("yyyy-MM-dd").format(table.reservationDate)}</td>
<td>${table.startTimeLimit.toString(timeForm)}</td>
<td>
<g:if test="${table.endTimeLimit != null}">
${table.endTimeLimit.toString(timeForm)}
</g:if>
<g:else>
<p>-</p>
</g:else>
</td>
<td>${table.hall}</td>
<g:if test="${table.places != 0}">
<td>${table.places}</td>
</g:if>
<g:else>
<td>-</td>
</g:else>
<%-- <td>${table.cost}</td>--%>
<td><g:link action="deleteReservedTable" params="[cafeeName: "${table.cafeeName.cafeeName}", cafeeAPI: "${table.cafeeName.apiInit}",
date: "${table.reservationDate }", startTime: "${table.startTimeLimit }", endTime: "${table.endTimeLimit }",
placesAmount: "${table.places }", cost: "${table.cost }", hall: "${table.hall}"]">Cancel</g:link></td>
</tr>
</g:each>
</tbody>
</table>
当我执行操作时,表中的一行是删除,但是当我重新加载页面时,另一行也将被删除。怎么避免呢?可能是,我必须清理GET / POST请求吗?怎么做?或者最好在删除之前附加警告?
def deleteReservedTable(params){
try {
def user = Person.findByUsername(springSecurityService.currentUser.username)
ApiRequest apiRequest
if(params['cafeeAPI'] != ""){
apiRequest = ApiHandlerController.request(params['cafeeAPI'], "TO_DELETE", params)
def myPlace = ReservedTable.findByVisitorAndCafeeName(user, Cafee.findByApiInit(params['cafeeAPI']))
myPlace.delete(flush: true)
}else{
def myPlace = ReservedTable.findByVisitorAndCafeeNameAndPlaces(user, Cafee.findByCafeeName(params['cafeeName']), Integer.parseInt(params['placesAmount']))
def cafee = Cafee.findByCafeeName(params['cafeeName'])
def table = TablePlacesInfo.where {
placesInTableAmount == Integer.parseInt(params['placesAmount'])
hall {
hallName == params['hall']
cafee {
cafeeName == cafee.getCafeeName()
}
}
}.get()
myPlace.delete(flush: true)
if(table != null){
table.tableForReservationAmount += 1
cafee.totalReservationPlaces += 1
if(!table.save(flush: true)){
table.errors.each{
println it
}
}
}
if(!cafee.save(flush: true)){
cafee.errors.each{
println it
}
}
}
showReservedTableForVisitor()
} catch (Exception e) {
render (view:'error.gsp')
e.printStackTrace()
}
}
答案 0 :(得分:2)
您的删除操作deleteReservedTable
应重定向回主视图。
基本上它应该是:
GET请求只应用于检索数据,POST可用于更新服务器上的状态