修正根据文章id查找username问题
This commit is contained in:
@@ -104,9 +104,10 @@ public class articleDao {
|
|||||||
articleEntity entity = null;
|
articleEntity entity = null;
|
||||||
try{
|
try{
|
||||||
conn = JdbcUtils.getConnection();
|
conn = JdbcUtils.getConnection();
|
||||||
|
preparedStatement.setInt(1, id);
|
||||||
preparedStatement = conn.prepareStatement(sql);
|
preparedStatement = conn.prepareStatement(sql);
|
||||||
rs = preparedStatement.executeQuery();
|
rs = preparedStatement.executeQuery();
|
||||||
preparedStatement.setInt(1, id);
|
|
||||||
while(rs.next()){
|
while(rs.next()){
|
||||||
int articleid = rs.getInt(1);
|
int articleid = rs.getInt(1);
|
||||||
int userid = rs.getInt(2);
|
int userid = rs.getInt(2);
|
||||||
@@ -122,8 +123,9 @@ public class articleDao {
|
|||||||
entity.setReadCount(readcount);
|
entity.setReadCount(readcount);
|
||||||
}
|
}
|
||||||
return entity;
|
return entity;
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
e.printStackTrace();
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -65,8 +65,19 @@ public class articleService {
|
|||||||
return JSONObject.toJSONString(dataMap1);
|
return JSONObject.toJSONString(dataMap1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public articleEntity selectByArticleId(int id){
|
public String selectByArticleId(int id){
|
||||||
return articleDao.selectByArticleId(id);
|
Map<String,Object> dataMap = new HashMap<>();
|
||||||
|
articleEntity articleEntity = articleDao.selectByArticleId(id);
|
||||||
|
String username = userDao.selectNameById(id);
|
||||||
|
dataMap.put("ArticleContent",articleEntity.getArticleContent());
|
||||||
|
dataMap.put("ArticleId",articleEntity.getArticleId());
|
||||||
|
dataMap.put("ArticleTitle",articleEntity.getArticleTitle());
|
||||||
|
dataMap.put("IsValid",articleEntity.getIsValid());
|
||||||
|
dataMap.put("ReadCount",articleEntity.getReadCount());
|
||||||
|
dataMap.put("username",username);
|
||||||
|
dataMap.put("publishtime",articleEntity.getPublishTime());
|
||||||
|
dataMap.put("articleico",articleEntity.getArticleIco());
|
||||||
|
return JSONObject.toJSONString(dataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public articleEntity updateReadCount(int id){
|
public articleEntity updateReadCount(int id){
|
||||||
|
@@ -35,14 +35,14 @@ public class selectByArticleId extends HttpServlet {
|
|||||||
|
|
||||||
|
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String articleid = req.getParameter("articleId");
|
String articleid = req.getParameter("id");
|
||||||
int id = Integer.parseInt(articleid);
|
int id = Integer.parseInt(articleid);
|
||||||
articleEntity entity = articleservice.selectByArticleId(id);
|
String jsonString = articleservice.selectByArticleId(id);
|
||||||
if(entity == null){
|
if(jsonString == null){
|
||||||
setResultError("该文章id不存在或已失效", writer);
|
setResultError("该文章id不存在或已失效", writer);
|
||||||
}else{
|
}else{
|
||||||
String jsonString = JSONObject.toJSONString(entity);
|
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
|
writer.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
public void setResult(Integer code, String msg, PrintWriter writer) {
|
||||||
|
Reference in New Issue
Block a user