数据库更新

This commit is contained in:
2023-07-08 00:57:38 +08:00
parent 04d5cfddb0
commit db1d14e740
4 changed files with 82 additions and 28 deletions

View File

@@ -95,4 +95,14 @@ public class commentEntity {
public void setUsername(String username) {
this.username = username;
}
String userUri;
public String getUserUri() {
return userUri;
}
public void setUserUri(String userUri) {
this.userUri = userUri;
}
}

View File

@@ -13,6 +13,7 @@ import java.util.Map;
public class commentService {
private commentDao commentDao =new commentDao();
private UserDao userDao = new UserDao();
//显示所有评论
public String selectByProjectId(String id){
@@ -51,6 +52,13 @@ public class commentService {
public String selectByUserId(int id){
List<commentEntity> commentEntityList = commentDao.selectByUserId(id);
for(int i =0;i<commentEntityList.size();i++)
{
int userId = commentEntityList.get(i).getUserId();
String username = userDao.selectNameById(userId);
commentEntityList.get(i).setUsername(username);
commentEntityList.get(i).setUserUri(userDao.selectUserByName(username).getUserAvatar());
}
return JSONObject.toJSONString(commentEntityList);
}
@@ -60,6 +68,7 @@ public class commentService {
if(trait.equals("last"))
{
commentEntityList = commentDao.selectByCreatTime(id);
}
if(trait.equals("hot"))
{
@@ -71,6 +80,8 @@ public class commentService {
int userid = commentEntity.getUserId();
String username = userDao.selectNameById(userid);
commentEntity.setUsername(username);
commentEntityList.get(i).setUsername(username);
commentEntityList.get(i).setUserUri(userDao.selectUserByName(username).getUserAvatar());
}
return JSONObject.toJSONString(commentEntityList);
}

View File

@@ -39,9 +39,8 @@ public class UploadHandleServlet extends HttpServlet {
response.setContentType("application/json;charset=UTF-8");
PrintWriter writer = response.getWriter();
HttpSession session = request.getSession();
userEntity userEntity ;
userEntity = (userEntity)session.getAttribute("user");
System.out.println(userEntity == null);
// userEntity userEntity ;
String userName = request.getParameter("username");
//得到上传文件的保存目录将上传的文件存放于WEB-INF目录下不允许外界直接访问保证上传文件的安全
String savePath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload");
savePath= this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload").replace("\\out\\artifacts\\helloGithub_war_exploded\\WEB-INF\\upload","\\web\\uploadFile");
@@ -163,9 +162,9 @@ public class UploadHandleServlet extends HttpServlet {
//删除处理文件上传时生成的临时文件
item.delete();
message = "文件上传成功!";
if(userEntity != null)
if(userName != null)
{
userService.updateUserAv(userEntity.getUserName(),realSavePath+"\\"+saveFilename);
userService.updateUserAv(userName,realSavePath+"\\"+saveFilename);
System.out.println("123");
}
@@ -184,8 +183,8 @@ public class UploadHandleServlet extends HttpServlet {
setResultError("文件上传失败",writer);
e.printStackTrace();
}
writer.println(saveFilename);
setResultOK(message,writer);
// writer.println(saveFilename);
// setResultOK(message,writer);
}
/**