其他分享
首页 > 其他分享> > 服务器查询

服务器查询

作者:互联网

今天在公司是继续做后台项目,写服务查询 双击能选中单词,比鼠标点击快,找到几张表dao,bead,servlet相同点,找到规律可以提高效率,/是引用过滤器

 

 

package org.lanqiao.servlet;

import java.io.IOException;
import java.util.List;

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 org.lanqiao.bean.Education;
import org.lanqiao.dao.EducationDao;
import org.lanqiao.dao.impl.EducationDaoImpl;

import com.google.gson.Gson;

@WebServlet("/Education")
public class EducationServlet extends BaseServlet {
EducationDao dao = new EducationDaoImpl();

Gson gson = new Gson();

/**
* 轩轩:扫地、拖地、窗玻璃、倒垃圾 丹丹:拖地 串:窗玻璃 光:倒垃圾
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.request = request;
this.response = response;

String type = getString("type");
System.out.println(type);
data.setMsg("");
if (!isNull("type")) {
switch (type) {
case "add":
add();
break;
case "delete":
delete();
break;
case "update":
update();
break;
case "select":
select();
break;
case "getCount":
getCount();
break;

default:
break;
}
} else {
data.setCode(3);
data.setMsg("缺少type参数");
}
response.getWriter().write(gson.toJson(data));
}

private void getCount() {
Integer i = dao.getCount();
if (i > 0) {
data.setCode(2);
data.setData(i);

} else {
data.setCode(3);
data.setMsg("服务器异常、请稍后再试!!!");
}
}

// 分页查询
private void select() {
// 默认第一页,可以手动更改
Integer pageIndex = isNull("pageIndex") ? 1 : getInt("pageIndex");
// 默认每页显示10条记录
Integer pageSize = isNull("pageSize") ? 10 : getInt("pageSize");
List<Education> getEducationPaging = dao.GetEducationPaging(pageIndex, pageSize);
// 返回回去的数据
data.setData(getEducationPaging);
}

private void update() {
System.out.println("update");
Integer userID = getInt("userID");
Integer startYear = getInt("startYear");
Integer endYear = getInt("endYear");
String schoolName=getString("schoolName");
Integer eduBackground = getInt("eduBackground");
String majorName=getString("majorName");
Integer eduOptions = getInt("eduOptions");


Integer id = getInt("id");

if (data.getMsg() != "") {
data.setCode(3);

return;
}

Integer i = dao.updateEducation(new Education(id, userID, startYear, endYear, schoolName,
eduBackground, majorName, eduOptions));
if (i > 0) {
data.setCode(2);
data.setData(i);

} else {
data.setCode(3);
data.setMsg("服务器异常、请稍后再试!!!");
}

}

private void delete() {
System.out.println("delete");
Integer id = getInt("id");
if (id == null) {
data.setCode(3);
data.setMsg("删除的id不能为空");
return;
}
Integer i = dao.deleteEducationById(id);
if (i > 0) {
data.setCode(2);
data.setData(i);
} else {
data.setCode(3);
data.setMsg("服务器异常、请稍后再试!!!");
}

}

private void add() {
System.out.println("update");
Integer userID = getInt("userID");
Integer startYear = getInt("startYear");
Integer endYear = getInt("endYear");
String schoolName=getString("schoolName");
Integer eduBackground = getInt("eduBackground");
String majorName=getString("majorName");
Integer eduOptions = getInt("eduOptions");

if (data.getMsg() != "") {
data.setCode(3);

return;
}
Integer i = dao.addEducation(new Education(userID, startYear, endYear, schoolName,
eduBackground, majorName, eduOptions));
if (i > 0) {
data.setCode(2);
data.setData(i);

} else {
data.setCode(3);
data.setMsg("服务器异常、请稍后再试!!!");
}
}
}

 

标签:setCode,import,dao,查询,getInt,Integer,服务器,data
来源: https://www.cnblogs.com/loveJavaJava/p/13573209.html