java - Spring JPA how to delete entry from ModelAndView and from view but leave it in db? -
i trying write web application can send messages between users. want add option allows remove message view, not db. how this?
controller:
@controller public class messagescontroller { @autowired private messageservice messageservice; @requestmapping(value = "/messages", method = requestmethod.get) modelandview messages(modelandview modelandview, @requestparam(value = "p", defaultvalue = "1") int p) { message message = new message(); authentication auth = securitycontextholder.getcontext().getauthentication(); list<message> inbox = messageservice.getinbox(auth.getname()); list<message> outbox = messageservice.getoutbox(auth.getname()); modelandview.setviewname("app.messages"); modelandview.getmodel().put("message", message); modelandview.getmodel().put("inbox", inbox); modelandview.getmodel().put("outbox", outbox); return modelandview; } @requestmapping(value = "/messages", method = requestmethod.post) modelandview messages(modelandview modelandview, message message) { modelandview.setviewname("app.messages"); authentication auth = securitycontextholder.getcontext().getauthentication(); message.setsender(auth.getname()); messageservice.send(message); return modelandview; } }
view:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <form:form commandname="message"> receiver: <form:input path="receiver" type="text" name="receiver" class="form-control"></form:input> title: <form:input path="title" type="text" name="title" class="form-control"> </form:input> content: <form:textarea path="content" name="content" rows="5" class="form-control"></form:textarea> <input type="submit" class="btn btn-default" value="send" /> </form:form> <br> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" href="#collapseinbox">inbox</a> </h4> </div> <div id="collapseinbox" class="panel-collapse collapse"> <table class="table table-striped"> <thead> <tr> <th>title</th> <th>from</th> <th>content</th> <th>date</th> </tr> </thead> <tbody> <c:foreach items="${inbox}" var="qwe"> <tr> <td class="col-md-2"><c:out value="${qwe.sender}"> </c:out></td> <td class="col-md-2"><c:out value="${qwe.title}"> </c:out></td> <td class="col-md-2"><c:out value="${qwe.content}"></c:out></td> <td class="col-md-2"><c:out value="${qwe.sent}"></c:out></td> </tr> </c:foreach> </table> <div class="panel-footer"></div> </div> </div> </div> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" href="#collapseoutbox">outbox</a> </h4> </div> <div id="collapseoutbox" class="panel-collapse collapse"> <table class="table table-striped"> <thead> <tr> <th>title</th> <th>to</th> <th>content</th> <th>date</th> </tr> </thead> <tbody> <c:foreach items="${outbox}" var="qwe"> <tr> <td class="col-md-2"><c:out value="${qwe.sender}"></c:out></td> <td class="col-md-2"><c:out value="${qwe.title}"></c:out></td> <td class="col-md-2"><c:out value="${qwe.content}"></c:out></td> <td class="col-md-2"><c:out value="${qwe.sent}"></c:out></td> </tr> </c:foreach> </table> <div class="panel-footer"></div> </div> </div> </div>
Comments
Post a Comment