增加onefile接口
This commit is contained in:
43
src/com/hellogithub/dao/fileDao.java
Normal file
43
src/com/hellogithub/dao/fileDao.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.hellogithub.dao;
|
||||
|
||||
import com.hellogithub.entity.fileEntity;
|
||||
import com.hellogithub.utils.JdbcUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class fileDao {
|
||||
|
||||
public List<fileEntity> selectFileEntity()
|
||||
{
|
||||
List<fileEntity> fileEntityList ;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql="select * from onefile ";
|
||||
fileEntityList = runner.query(conn,sql,new BeanListHandler<>(fileEntity.class));
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return fileEntityList;
|
||||
}
|
||||
public fileEntity selectFileEntityById(int id )
|
||||
{
|
||||
fileEntity fileEntity ;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql="select * from onefile where id = ?";
|
||||
fileEntity = runner.query(conn,sql,new BeanHandler<>(fileEntity.class),id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return fileEntity;
|
||||
}
|
||||
}
|
86
src/com/hellogithub/entity/fileEntity.java
Normal file
86
src/com/hellogithub/entity/fileEntity.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.hellogithub.entity;
|
||||
|
||||
public class fileEntity {
|
||||
int id;
|
||||
String oneFileName;
|
||||
String language;
|
||||
String description;
|
||||
|
||||
int userId;
|
||||
String url;
|
||||
int lookNum;
|
||||
String Content;
|
||||
int isValid;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getOneFileName() {
|
||||
return oneFileName;
|
||||
}
|
||||
|
||||
public void setOneFileName(String oneFileName) {
|
||||
this.oneFileName = oneFileName;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getLookNum() {
|
||||
return lookNum;
|
||||
}
|
||||
|
||||
public void setLookNum(int lookNum) {
|
||||
this.lookNum = lookNum;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return Content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public int getIsValid() {
|
||||
return isValid;
|
||||
}
|
||||
|
||||
public void setIsValid(int isValid) {
|
||||
this.isValid = isValid;
|
||||
}
|
||||
}
|
12
src/com/hellogithub/service/oneFileService.java
Normal file
12
src/com/hellogithub/service/oneFileService.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.hellogithub.service;
|
||||
|
||||
import com.hellogithub.dao.fileDao;
|
||||
import com.hellogithub.entity.fileEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class oneFileService {
|
||||
private fileDao fileDao = new fileDao();
|
||||
public List<fileEntity> selectFileEntity(){return fileDao.selectFileEntity(); }
|
||||
public fileEntity selectFileEntityById(int id ){return fileDao.selectFileEntityById(id); }
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.hellogithub.servlet.systemAdmin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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("/selectFileById")
|
||||
public class selectFileByIdServlet 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");
|
||||
String jsonString = JSONObject.toJSONString(oneFileService.selectFileEntityById(Integer.parseInt(id)));
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.println(jsonString);
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package com.hellogithub.servlet.systemAdmin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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("/selectFile")
|
||||
public class selectFileServlet 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 jsonString = JSONObject.toJSONString(oneFileService.selectFileEntity());
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.println(jsonString);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user