惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧!

1、获取搜索条件值
function searchStudent(){
$('#dg').datagrid('load',{
stuNo:$('#s_stuNo').val(),
stuName:$('#s_stuName').val(),
sex:$('#s_sex').combobox("getValue"),
bbirthday:$('#s_bbirthday').datebox("getValue"),
ebirthday:$('#s_ebirthday').datebox("getValue"),
gradeId:$('#s_gradeId').combobox("getValue")
});
} 2、servlet
String stuNo=request.getParameter("stuNo");
String stuName=request.getParameter("stuName");
String sex=request.getParameter("sex");
String bbirthday=request.getParameter("bbirthday");
String ebirthday=request.getParameter("ebirthday");
String gradeId=request.getParameter("gradeId"); Student student= new Student();
if(stuNo!=null){
student.setStuNo(stuNo);
student.setStuName(stuName);
student.setSex(sex);
if(StringUtil.isNotEmpty(gradeId)){
student.setGradeId(Integer.parseInt(gradeId));
}
}
//获取page、rows请求
String page=request.getParameter("page");
String rows=request.getParameter("rows"); //封装
PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(rows)); Connection con=null;
try {
con=dbUtil.getCon();
JSONObject result=new JSONObject();
JSONArray jsonArray=JsonUtil.formatRsToJsonArray(studentDao.studentList(con, pageBean,student,bbirthday,ebirthday));
int total=studentDao.studentCount(con,student,bbirthday,ebirthday);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(response, result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} 3、查询dao
public ResultSet studentList(Connection con,PageBean pageBean,Student student,String bbirthday,String ebirthday)throws Exception{
StringBuffer sb=new StringBuffer("select * from t_student s,t_grade g where s.gradeId=g.id");
if(StringUtil.isNotEmpty(student.getStuNo())){
sb.append(" and s.stuNo like '%"+student.getStuNo()+"%'");
}
if(StringUtil.isNotEmpty(student.getStuName())){
sb.append(" and s.StuName like '%"+student.getStuName()+"%'");
}
if(StringUtil.isNotEmpty(student.getSex())){
sb.append(" and s.sex ='"+student.getSex()+"'");
}
if(student.getGradeId()!=-1){
sb.append(" and s.GradeId ='"+student.getGradeId()+"'");
}
if(StringUtil.isNotEmpty(bbirthday)){
sb.append(" and TO_DAYS(s.birthday)>=TO_DAYS('"+bbirthday+"')");
}
if(StringUtil.isNotEmpty(ebirthday)){
sb.append(" and TO_DAYS(s.birthday)<=TO_DAYS('"+ebirthday+"')");
} if(pageBean!=null){
sb.append(" limit "+pageBean.getStart()+","+pageBean.getRows());
}
PreparedStatement pstmt=con.prepareStatement(sb.toString());
return pstmt.executeQuery();
} public int studentCount(Connection con,Student student,String bbirthday,String ebirthday)throws Exception{
StringBuffer sb=new StringBuffer("select count(*) as total from t_student s,t_grade g where s.gradeId=g.id");
if(StringUtil.isNotEmpty(student.getStuNo())){
sb.append(" and s.stuNo like '%"+student.getStuNo()+"%'");
}
if(StringUtil.isNotEmpty(student.getStuName())){
sb.append(" and s.StuName like '%"+student.getStuName()+"%'");
}
if(StringUtil.isNotEmpty(student.getSex())){
sb.append(" and s.sex ='"+student.getSex()+"'");
}
if(student.getGradeId()!=-1){
sb.append(" and s.GradeId ='"+student.getGradeId()+"'");
}
if(StringUtil.isNotEmpty(bbirthday)){
sb.append(" and TO_DAYS(s.birthday)>=TO_DAYS('"+bbirthday+"')");
}
if(StringUtil.isNotEmpty(ebirthday)){
sb.append(" and TO_DAYS(s.birthday)<=TO_DAYS('"+ebirthday+"')");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString());
ResultSet rs=pstmt.executeQuery();
if(rs.next()){
return rs.getInt("total");
}else{
return 0;
}
} 4、删除dao
public int studentDelect(Connection con,String delIds)throws Exception{
String sql="delete from t_student where stuId in("+delIds+")";
PreparedStatement pstmt=con.prepareStatement(sql);
return pstmt.executeUpdate();
} 5、删除servlet
String delIds=request.getParameter("delIds"); Connection con=null;
try {
con=dbUtil.getCon();
JSONObject result=new JSONObject();
int delNums=studentDao.studentDelect(con, delIds);
if(delNums>0){
result.put("success", "true");
result.put("delNums", delNums);
}else{
result.put("errorMeg", "删除失败");
}
result.put("delNum", delNums);
ResponseUtil.write(response, result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
dbUtil.closeCon(con);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} 6、修改web.xml
<servlet>
<servlet-name>studentDeleteServlet</servlet-name>
<servlet-class>com.java1234.web.StudentDeleteServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>studentDeleteServlet</servlet-name>
<url-pattern>/studentDelete</url-pattern>
</servlet-mapping> 7、删除前端
function deleteStudent(){
var selectedRows=$("#dg").datagrid('getSelections');
if(selectedRows.length==0){
$.messager.alert("系统提示","请选择要删除的数据!");
return;
}
var strIds=[];
for(var i=0;i<selectedRows.length;i++){
strIds.push(selectedRows[i].stuId);
}
var ids=strIds.join(",");
$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗?",function(r){
if(r){
$.post("studentDelete",{delIds:ids},function(result){
if(result.success){
$.messager.alert("系统提示","您已成功删除<font color=red>"+result.delNum+"</font>条数据!");
$("#dg").datagrid("reload");
}else{
$.messager.alert("系统提示",result.errorMsg);
}
},"json");
}
});
}

Jsp&Servlet入门级项目全程实录第7讲的更多相关文章

  1. Jsp&Servlet入门级项目全程实录第1讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.jdbc数据库连接(略) 2.登录表单 2.1设置内边距 <dir style="padding- ...

  2. Jsp&Servlet入门级项目全程实录第8讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.添加dao public int studentAdd(Connection con,Student studen ...

  3. Jsp&Servlet入门级项目全程实录第4讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.添加搜索.添加.修改.删除按钮 <div id="tb"> <div> ...

  4. Jsp&Servlet入门级项目全程实录第3讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.建立数据表及数据(略) 2.装载驱动,建立数据表 <link rel="stylesheet&qu ...

  5. Jsp&Servlet入门级项目全程实录第2讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.导入jquery-easyui-1.3.3包( http://www.jeasyui.com/) 2.在页面导入e ...

  6. Jsp&Servlet入门级项目全程实录第6讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.建立数据表及数据(略) 2.创建student model package com.java1234.model; ...

  7. Jsp&Servlet入门级项目全程实录第5讲

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 1.修改功能实现 dao public int gradeAdd(Connection con,Grade grade ...

  8. JSP/Servlet Web应用中.properties文件的放置与读取

    本地项目 在本地类库中,我经常使用当前目录来放置.properties文件,这时调用方只要引用我的jar,并且将我的.properties放在他的classpath里面即可,比如: p.load(ne ...

  9. 创建jsp+Servlet+JavaBean+JDBC+MySQL项目的过程

    1 根据需求建立Mysql数据,确立数据库的表的字段.属性.主键,外键等.下面我使用的数据库名dev ,表名user,字段  name,设置为主键.用户名不能为空,字段password,密码 2 在E ...

随机推荐

  1. C# Lock锁(个人随记)

    先看看为什么要用锁 需求:多线程处理值的加减   static int NoLockData = 0; public static void NoLockNormalTest(int threadIn ...

  2. 敏捷项目-依赖项拖动change

    1. 2.类方法插入数据.

  3. 程序媛计划——python初级课时3~5

    产生1-10中的随机数: for 循环:所有可遍历对象都能用于for循环,如一个字符串. len(list),list中的元素类型可以各不相同:可以直接用下标对list元素赋值来更新列表 对字符串可以 ...

  4. IDEA批量修改变量名操作

    批量修改变量名操作:shift+F6选中变量---->修改变量---->Enter回车

  5. Servlet实现session读写

    前言     一个女人让他的程序员丈夫去商店买东西:你去附近的商店买些面包,如果有鸡蛋的话,买6个回来,这个丈夫买了6个面包回来,他的妻子大吃一惊:你为什么买了6个面包?! 程序员丈夫回答:因为他们有 ...

  6. jzoj4724

    DJL为了避免成为一只咸鱼,来找czgj学习Fibonacci数列. 通过czgj的谆谆教导,DJL明白了Fibonacci数列是这样定义的: F(1)=1;F(2)=1;F(n)=F(n-1)+F( ...

  7. 转载:在spring中嵌入activemq

    转载:http://www.dev26.com/blog/article/137 web开发站中的邮件发送使用了activemq我这是从网上找的进行了一些修改,记录下来,为了避免发送邮件时程序对用户操 ...

  8. 构建RequestDelegate管道

    1. 创建 Context.cs using System; using System.Threading.Tasks; namespace MyPipeline { public class Con ...

  9. Java多线程实现异步调用

    在Java平台,实现异步调用的角色有如下三个角色:调用者. 提货单 .真实数据,一个调用者在调用耗时操作,不能立即返回数据时,先返回一个提货单 .然后在过一断时间后凭提货单来获取真正的数据.去蛋糕店买 ...

  10. Alamofire源码导读五:错误表示

    AFError is the error type returned by Alamofire. It encompasses a few different types of errors, eac ...