三个接口
This commit is contained in:
@@ -6,10 +6,7 @@ import com.hellogithub.utils.JdbcUtils;
|
|||||||
import org.apache.commons.dbutils.QueryRunner;
|
import org.apache.commons.dbutils.QueryRunner;
|
||||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AdminDao {
|
public class AdminDao {
|
||||||
@@ -41,20 +38,80 @@ public class AdminDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int updateAdminLoginTime(String name){
|
public int updateAdminLoginTime(String name,String loginTime){
|
||||||
String label="";
|
|
||||||
int num;
|
int num;
|
||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE user SET searchHistory = ? WHERE userName= ? and isValid = 1";
|
String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1";
|
||||||
num = runner.update(conn,sql,label,name);
|
num = runner.update(conn,sql,loginTime,name);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 根据用户名查询管理员
|
||||||
|
* */
|
||||||
|
public adminEntity findByAdminName(String adminName) {
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
Connection connection = null;
|
||||||
|
try {
|
||||||
|
connection = JdbcUtils.getConnection();
|
||||||
|
String Sql = "select * from admin where adminName=? and isValid = 1";
|
||||||
|
preparedStatement = connection.prepareStatement(Sql);
|
||||||
|
preparedStatement.setString(1, adminName);
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
if (!resultSet.next()) { // 查询不到用户数据
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 将db中数据 返回给客户端 查询到数据
|
||||||
|
Integer id = resultSet.getInt(1);
|
||||||
|
String dbUserName = resultSet.getString(2);
|
||||||
|
String dbUserPwd = resultSet.getString(3);
|
||||||
|
adminEntity adminEntity = new adminEntity(dbUserName, dbUserPwd);
|
||||||
|
return adminEntity;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
JdbcUtils.closeConnection(resultSet, preparedStatement, connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员注册
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
public int adminRegister(String adminName,String adminPwd){
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
try {
|
||||||
|
connection = JdbcUtils.getConnection();
|
||||||
|
// sql语句写的操作 ----加上事务
|
||||||
|
JdbcUtils.beginTransaction(connection); // 开启事务
|
||||||
|
String insertSql = "INSERT INTO admin (adminId, adminName, adminPassword,isValid,loginTime) VALUES (null, ?,?,1,?);";
|
||||||
|
preparedStatement = connection.prepareStatement(insertSql);
|
||||||
|
preparedStatement.setString(1,adminName);
|
||||||
|
preparedStatement.setString(2, adminPwd);
|
||||||
|
Date time= new java.sql.Date(new java.util.Date().getTime());
|
||||||
|
preparedStatement.setDate(3, time);
|
||||||
|
int result = preparedStatement.executeUpdate();
|
||||||
|
// 代码执行没有问题的情况下 则会提交数据
|
||||||
|
JdbcUtils.commitTransaction(connection); // 提交事务
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 程序代码报错之后 是需要回滚事务
|
||||||
|
e.printStackTrace();
|
||||||
|
JdbcUtils.rollBackTransaction(connection);// 回滚事务
|
||||||
|
return 0;
|
||||||
|
} finally {
|
||||||
|
JdbcUtils.closeConnection(preparedStatement, connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@@ -87,4 +87,13 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void LevelUp(String username){userDao.LevelUp(username);}
|
public void LevelUp(String username){userDao.LevelUp(username);}
|
||||||
|
|
||||||
|
|
||||||
|
public List<userEntity> selectAllUser(){return userDao.selectAllUser(); }
|
||||||
|
|
||||||
|
public int updateUserDetail(int userId ,String userName , String userPassword, String creatTime ,int isValid ,int projectNum ,String searchHistory ,int contributionValue, String userAvatar ,int userLevel)
|
||||||
|
{
|
||||||
|
return userDao.updateUserDetail( userId , userName , userPassword, creatTime , isValid , projectNum , searchHistory , contributionValue, userAvatar , userLevel);
|
||||||
|
}
|
||||||
|
public int deleteUser(int id ){return userDao.deleteUser(id); }
|
||||||
}
|
}
|
||||||
|
@@ -97,4 +97,9 @@ public class commentService {
|
|||||||
}
|
}
|
||||||
return tip;
|
return tip;
|
||||||
}
|
}
|
||||||
|
public List<commentEntity> selectAllComment(){return commentDao.selectAllComment();}
|
||||||
|
public int updateCommentDetail(int commentId , int userId , int projectId, String content ,int isUsed ,String commentTime ,int isValid ,int star, int likeNum ){
|
||||||
|
return commentDao.updateCommentDetail( commentId , userId , projectId, content , isUsed ,commentTime ,isValid ,star, likeNum );
|
||||||
|
}
|
||||||
|
public int deleteComment(int id ){return commentDao.deleteComment(id);}
|
||||||
}
|
}
|
||||||
|
@@ -281,4 +281,13 @@ public class projectService {
|
|||||||
public int selectProjectByPname(String projectName){
|
public int selectProjectByPname(String projectName){
|
||||||
return projectDao.selectProjectByPname(projectName);
|
return projectDao.selectProjectByPname(projectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<projectEntity> selectAllProject(){return projectDao.selectAllProject();}
|
||||||
|
|
||||||
|
public int updateProjectDetail(int projectId , int userId , String projectName, String projectUrl ,String projectIco ,String projectTitle ,String projectDescription ,int startNum, String submitTime ,int categoryId,int isValid,String fileAddress,int periodicals,int lookCount)
|
||||||
|
{
|
||||||
|
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);}
|
||||||
}
|
}
|
Reference in New Issue
Block a user