增加addFileServlet
This commit is contained in:
@@ -40,4 +40,19 @@ public class fileDao {
|
||||
}
|
||||
return fileEntity;
|
||||
}
|
||||
|
||||
public int addLookCount(int id )
|
||||
{
|
||||
int num ;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql="update onefile set lookNum = lookNum + 1 where id = ?";
|
||||
num = runner.update(conn,sql,id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
@@ -41,4 +41,5 @@ public class oneFileService {
|
||||
fileEntity.setUserName(userName);
|
||||
return fileEntity;
|
||||
}
|
||||
public int addLookCount(int id ){return fileDao.addLookCount(id);}
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
package com.hellogithub.servlet.systemAdmin;
|
||||
|
||||
import com.hellogithub.service.oneFileService;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
@WebServlet("/addFileLookCount")
|
||||
public class addFileLookCountServlet extends HttpServlet {
|
||||
private oneFileService oneFileService = new oneFileService();
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("text/html; charset=utf-8");
|
||||
// 设置响应头允许ajax跨域访问
|
||||
String curOrigin = req.getHeader("Origin");
|
||||
resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
|
||||
resp.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
|
||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
String id =req.getParameter("id");
|
||||
int num = oneFileService.addLookCount(Integer.parseInt(id));
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.println(num);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user