下面展示一些 内联代码片
。
id查询
// An highlighted block
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
SqlSession session = MyBatisUtil.getSqlSession();
StudentDao dao=session.getMapper(StudentDao.class);
String stuid=request.getParameter("stuid");
Student i=dao.selid(Integer.parseInt(stuid));
Gson g=new Gson();
PrintWriter out=response.getWriter();
if (i!=null) {
out.print(g.toJson(i));
}
out.close();
添加
// An highlighted block
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
SqlSession session = MyBatisUtil.getSqlSession();
StudentDao dao=session.getMapper(StudentDao.class);
/**
* 接前台参数
*/
String name=request.getParameter("name");
String tele_number=request.getParameter("tele_number");
String student_sex=request.getParameter("student_sex");
String born_date=request.getParameter("born_date");
String department=request.getParameter("department");
String address=request.getParameter("address");
String id=request.getParameter("id");
Student stu=new Student();
stu.setStudent_name(name);
stu.setTele_number(tele_number);
stu.setStudent_sex(student_sex);
stu.setBorn_date(born_date);
stu.setDepartment(department);
stu.setAddress(address);
stu.setStudent_id(Integer.parseInt(id));
int i=dao.update(stu);
session.commit();
PrintWriter out=response.getWriter();
if (i>0) {
out.print(true);
}else {
out.print(false);
}
out.close();
分页
// An highlighted block
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
SqlSession session = MyBatisUtil.getSqlSession();
StudentDao dao=session.getMapper(StudentDao.class);
/**
* 接前台参数
*/
String name=request.getParameter("name");
String tele_number=request.getParameter("tele_number");
String minborn_date=request.getParameter("minborn_date");
String maxborn_date=request.getParameter("maxborn_date");
String limit=request.getParameter("limit");
String page=request.getParameter("page");
Dto dto=new Dto();
dto.setStudent_name(name);
dto.setTele_number(tele_number);
dto.setMinborn_date(minborn_date);
dto.setMaxborn_date(maxborn_date);
dto.setPage(Integer.parseInt(page));
dto.setPageSize(Integer.parseInt(limit));
int num=dao.count(dto);
List<Student> list=dao.sel(dto);
/**
* 数据转json
*/
Gson g=new Gson();
Map<String, Object> map=new HashMap<String, Object>();
map.put("code", 0);
map.put("count", num);
map.put("data", list);
PrintWriter out=response.getWriter();
out.print(g.toJson(map));
out.close();