目录
CommunityEventRegistrationService
jsp部分摘要
<c:forEach items="${sessionScope.CommunityEventRegistrationList}" var="cer">
<form class="form-horizontal" action="/CommunityEventRegistrationDelete" method="post">
<a class="btn btn-danger" href="/CommunityEventRegistrationDelete?id=1&username=${cer.username }">
删除
</a>
</form>
</c:forEach>
其中href="/CommunityEventRegistrationDelete?id=1&username=${cer.username }"
CommunityEventRegistrationDelete为指向的Servlet
传两个值,一个是id,一个是username。【这里展示的是两种不同形式】
Servlet部分摘要
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("username");
boolean isSuccess = cerService.update(communityeventregistration,s1.substring(7),id,name);
if(isSuccess) {
request.setAttribute("msg", "删除成功!可刷新查看!");
}else {
request.setAttribute("failMsg", "删除失败!");
}
jsp传值过来后,Servlet就用request.getParameter("???");来接收
然后id,name可以这样
boolean isSuccess = cerService.update(communityeventregistration,s1.substring(7),id,name);
塞在后面,传值进Service类使用方法进入后续操作
CommunityEventRegistrationService
public class CommunityEventRegistrationService{
private CommunityEventRegistrationDao cerDao = new CommunityEventRegistrationDao();
public boolean update(CommunityEventRegistration communityeventregistration,String phone,int id,String name) {
try {
cerDao.update(communityeventregistration, phone, id, name);
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
}
CommunityEventRegistrationDao
public class CommunityEventRegistrationDao {
public void update(CommunityEventRegistration communityeventregistration, String phone,int id, String username) throws SQLException {
QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());
System.out.println("update在此1");
if(id==1){
System.out.println("update在此2");
String sql = "update `communityeventregistration` set yoga='-----' where phone = ? and username=? and yoga= '√'";
r.update(sql,phone,username);
}
}
}