往project中更新数据

This commit is contained in:
cyk
2023-07-05 17:49:29 +08:00
parent b4c9767455
commit 1a902ca4a6
2 changed files with 35 additions and 2 deletions

View File

@@ -236,4 +236,33 @@ public class projectDao {
}
return projectEntityList;
}
public int addStarNum(int proId)
{
int num ;
try {
Connection conn = JdbcUtils.getConnection();
QueryRunner runner = new QueryRunner();
String sql = "update project set starNum = starNum + 1 where isValid = 1 and projectId= ?";
num = runner.update(conn, sql,proId);
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return num;
}
public int cancelStarNum(int proId)
{
int num ;
try {
Connection conn = JdbcUtils.getConnection();
QueryRunner runner = new QueryRunner();
String sql = "update project set starNum = starNum - 1 where isValid = 1 and projectId= ?";
num = runner.update(conn, sql,proId);
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
return num;
}
}

View File

@@ -1,12 +1,14 @@
package com.hellogithub.service;
import com.hellogithub.dao.UserDao;
import com.hellogithub.dao.projectDao;
import com.hellogithub.dao.supportDao;
import com.hellogithub.entity.supportEntity;
public class supportService {
private supportDao supportDao = new supportDao();
private UserDao userDao = new UserDao();
private projectDao projectDao = new projectDao();
public int retNum(String username,int projectId){
int num ;
supportEntity supportEntity = supportDao.selectSupport(userDao.selectIdByName(username),projectId);
@@ -24,7 +26,8 @@ public class supportService {
{
String tip;
int num = supportDao.insertSupport(userDao.selectIdByName(username),projectId);
if(num == 1)
int numm = projectDao.addStarNum(projectId);
if(num == 1 & numm == 1)
{
tip="点赞成功";
}
@@ -38,7 +41,8 @@ public class supportService {
{
String tip;
int num = supportDao.deleteSupport(userDao.selectIdByName(username),projectId);
if(num == 1)
int numm = projectDao.cancelStarNum(projectId);
if(num == 1 & numm == 1)
{
tip="取消成功";
}