修改外键约束
This commit is contained in:
@@ -418,6 +418,14 @@ public class UserDao {
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql="delete from user where userId = ?";
|
||||
num = runner.update(conn,sql,id);
|
||||
sql="update project set isValid = 0 where userId = ?";
|
||||
runner.update(conn,sql,id);
|
||||
sql="delete from support where userId = ?";
|
||||
runner.update(conn,sql,id);
|
||||
sql="delete from comment where userId = ?";
|
||||
runner.update(conn,sql,id);
|
||||
sql="update article set isValid = 0 where userId = ?";
|
||||
runner.update(conn,sql,id);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@@ -128,7 +128,7 @@ public class commentDao {
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql="update project set userId = ? , projectId = ? , content = ? ,isUsed =?, commentTime=?, isValid=?,star=?,likeNum=?where commentId =? ";
|
||||
String sql="update comment set userId = ? , projectId = ? , content = ? ,isUsed =?, commentTime=?, isValid=?,star=?,likeNum=?where commentId =? ";
|
||||
num = runner.update(conn,sql,userId, projectId , content , isUsed, commentTime, isValid, star, likeNum ,commentId);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -142,7 +142,7 @@ public class commentDao {
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql="delete from project where commentId = ?";
|
||||
String sql="delete from comment where commentId = ?";
|
||||
num = runner.update(conn,sql,id);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@@ -369,10 +369,12 @@ public class projectDao {
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
runner.update(conn,"set foreign_key_checks = 0");
|
||||
String sql="delete from project where projectId = ?";
|
||||
num = runner.update(conn,sql,id);
|
||||
runner.update(conn,"set foreign_key_checks = 1");
|
||||
sql="delete from support where projectId = ?";
|
||||
runner.update(conn,sql,id);
|
||||
sql="delete from project_category where projectId = ?";
|
||||
runner.update(conn,sql,id);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@@ -289,5 +289,12 @@ public class projectService {
|
||||
{
|
||||
return projectDao.updateProjectDetail( projectId , userId , projectName, projectUrl , projectIco , projectTitle , projectDescription , startNum, submitTime ,categoryId,isValid,fileAddress, periodicals, lookCount);
|
||||
}
|
||||
public int deleteProject(int id ){return projectDao.deleteProject(id);}
|
||||
public int deleteProject(int id )
|
||||
{
|
||||
int userId = projectDao.selectProById(String.valueOf(id)).getUserId();
|
||||
String userName= userDao.selectNameById(userId);
|
||||
userEntity userEntity = userDao.selectUserByName(userName);
|
||||
userDao.updateUserDetail(userEntity.getUserId(),userName,userEntity.getUserPassword(),userEntity.getCreatTime(),userEntity.getIsValid(),userEntity.getProjectNum()-1,userEntity.getSearchHistory(),userEntity.getContributionValue(),userEntity.getUserAvatar(),userEntity.getUserLevel());
|
||||
return projectDao.deleteProject(id);
|
||||
}
|
||||
}
|
@@ -35,7 +35,6 @@ public class deleteProjectServlet extends HttpServlet {
|
||||
|
||||
String proId = req.getParameter("id");
|
||||
PrintWriter writer = resp.getWriter();
|
||||
|
||||
int num = projectService.deleteProject(Integer.parseInt(proId));
|
||||
if(num == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user