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