`
hongzhguan
  • 浏览: 272034 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Ext中实现EditorGridPanel的增删改操作(2)

    博客分类:
  • Ext
阅读更多
public ActionForward showStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
//设置编码
response.setContentType("text/html;charset=gbk");
PrintWriter out=response.getWriter();
//获取分页的pageIndex和pageSize的值
int pageIndex=Integer.parseInt(request.getParameter("start").toString());
int pageSize=Integer.parseInt(request.getParameter("limit").toString());
//获取总的记录条数
int pageCount=this.iservice.getCountByHQL("from Student");
Student stu=null;
//获取分页后的所有的学生的信息
List<Student> list=this.iservice.showByDetachedCriteria(DetachedCriteria.forClass(Student.class), pageIndex,pageSize);
String json="{totalProperty:"+pageCount+",root:[";
for (int i = 0; i < list.size(); i++) {
stu=(Student)list.get(i);
     json+="{stuid:"+stu.getStuid()+",stuname:'"+stu.getStuname()+"',stuage:"+stu.getStuage()+",gradename:'"+stu.getGrade().getGradename()+"',teacher:'"+stu.getGrade().getTeacher()+"',address:'"+stu.getAddress()+"'},";
}
//截取json
json=json.substring(0,json.length()-1);
json+="]}";
out.write(json);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public ActionForward addStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;
try {
response.setCharacterEncoding("gbk");
PrintWriter out=response.getWriter();
this.iservice.save(studentForm.getStu());
out.write("{success:true,msg:'添加学生信息成功!'}");
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

//批量修改学生的信息
public ActionForward updateStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
response.setCharacterEncoding("gbk");
PrintWriter out=response.getWriter();
String json=request.getParameter("stuJson").toString();
json="{'data':"+json+"}";
//将json中的值遍历出来
//格式为"{"data":[{"id":"1"},{"id:"2"}]},
JSONObject jsonObject=new JSONObject(json);
//获得json数组
JSONArray jsonArray=jsonObject.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo=jsonArray.getJSONObject(i);
//获取班级的编号
Long stuid=Long.valueOf(jo.get("stuid").toString());
Student stu=(Student)this.iservice.get(Student.class,stuid);
//获取其他的值
String stuname=jo.getString("stuname").toString();
Long stuage=jo.getLong("stuage");
String gradename=jo.getString("gradename");
String teacher=jo.getString("teacher");
String address=jo.getString("address");
//将值添加设置给stu
stu.setStuname(stuname);
stu.setStuage(stuage);
stu.setAddress(address);
stu.getGrade().setGradename(gradename);
stu.getGrade().setTeacher(teacher);
//调用修改的方法
this.iservice.update(stu);
}
out.write("修改学生信息成功!");
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

//右键菜单中修改学生的信息
public ActionForward updateOneStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

PrintWriter out=null;
try {
response.setContentType("text/html;charset=gbk");
out=response.getWriter();

//获取传递过来的json字符串数组===============>此数组返回的是修改后的字段值
String modified=request.getParameter("array");
String modifieStr[]=modified.split("\\|\\|");
for (int i = 0; i <modifieStr.length; i++) {
String json="{";//保存构造后的json
//在将字符串分隔
String modifiedS[]=modifieStr[i].split("=>");
modifiedS[1]=modifiedS[1].substring(1);
json+=modifiedS[0]+","+modifiedS[1];
//将构造的json字符串转换成JSONObject对象
JSONObject jso=new JSONObject(json);
//获取班级中的信息
Long stuId=jso.getLong("stuid");
//获取学生对象
Student stu=(Student)this.iservice.get(Student.class,stuId);
//判断jso中是否有该键值
if(jso.has("stuname")){
stu.setStuname(jso.getString("stuname"));
}
if(jso.has("stuage")){
stu.setStuage(jso.getLong("stuage"));
}
if(jso.has("gradename")){
stu.getGrade().setGradename(jso.getString("gradename"));
}
if(jso.has("teacher")){
stu.getGrade().setTeacher(jso.getString("teacher"));
}
if(jso.has("address")){
stu.setAddress(jso.getString("address"));
}

//修改学生的信息
this.iservice.update(stu);
}
out.write("{msg:true}");
} catch (Exception e) {
   out.write("{msg:false}");
e.printStackTrace();
}finally{
out.flush();
out.close();
}
return null;
}


public ActionForward delStudent(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Long id=Long.valueOf(request.getParameter("id").toString());
Student stu=(Student)this.iservice.get(Student.class, id);
this.iservice.delete(stu);
return null;
}
分享到:
评论

相关推荐

    Ext.net后台分页增删改

    在"Ext.NET后台分页增删改"这个主题中,我们将探讨如何利用Ext.NET实现数据库后台分页、树形视图操作以及Grid面板的CRUD(创建、读取、更新和删除)功能。 首先,让我们深入了解一下后台分页。在Ext.NET中,为了...

    可编辑表格Ext.grid.EditorGridPanel

    2. Ext.grid.EditorGridPanel:EditorGridPanel是Ext JS中的一种网格组件,它扩展了GridPanel,增加了单元格级别的编辑功能。用户可以直接在表格中修改数据,而无需跳转到单独的编辑页面。 二、核心特性 1. 可编辑...

    Ext可编辑的tree,EditorGridPanel

    因为项目的需求,实现一个可以编辑的tree,在网上找了一个牛人写的控件.Ext.ux.maximgb.tg.EditorGridPanel 把源码下载下来以后 不能运行,自己根据给出的列子,另写了一个小程序.不过并没有与数据库交互.

    ext 读取xml 可编辑grid

    在EXT JS框架中,"ext 读取xml 可编辑grid"是一个常见的需求,涉及到的主要知识点包括EXT的数据对象、EditorGridPanel的使用以及EXT对XML数据格式的支持。下面将详细阐述这些内容。 EXT JS是一个强大的JavaScript库...

    Ext 连接数据库的相关操作

    首先,EXT中的Editgridpanel是一个可编辑的表格组件,用于显示和编辑数据。它集成了数据绑定和行编辑功能,非常适合于数据管理界面。要将Editgridpanel与数据库连接,我们需要创建一个数据源,这通常是通过EXT的...

    ext的edittreegrid实现

    在EXT JS库中,"ext的edittreegrid实现"是一种功能强大的组件,它结合了树形视图(Tree)和编辑网格(EditorGrid)的功能,允许用户在具有层次结构的数据上进行直观的编辑操作。这个组件对于那些需要管理结构化且...

    解决editorgridpanel编辑时视图向右移动的问题

    通常,这样的修复代码会包括对上述策略的实现,比如使用`Ext.util.CSS`来修改样式,或者在`beforeedit`和`afteredit`事件中处理滚动条和视图的位置。为了进一步了解并应用这个修复,我们需要查看`bugfix.js`的内容,...

    给Extjs的GridPanel增加“合计”行

    在实际应用中,我们经常需要在GridPanel底部显示一行“合计”行,以便对某一列或多列的数据进行求和或其他统计操作。这篇博文“给Extjs的GridPanel增加‘合计’行”将指导我们如何实现这一功能。 首先,我们需要...

    EXT2.0 GRID 示例

    3. **行编辑**:EXT GRID支持行内编辑,用户可以直接在表格中修改数据,这需要结合EditorGridPanel和Form Field组件来实现。 4. **排序和过滤**:GRID可以实现列点击排序,通过配置`sortable`属性和`sortInfo`对象...

    Ext组件说明 Ext组件概述

    BoxComponent是Ext中的基本布局容器,可以用来控制子元素的位置和大小。通过调整BoxComponent的配置选项,开发者可以实现灵活的布局设计。 ##### 2. **Button(按钮组件)** Button组件是Web应用中最常见的交互...

    Ext3.0 api帮助文档

    - **Ext.grid.EditorGridPanel**: 提供单元格级别的编辑功能。 6. **表单(Forms)** - **Ext.form.FormPanel**: 创建表单的容器,支持多种表单元素和验证。 - **Ext.form.Field**: 表单字段类,如文本框、选择...

    Extjs可编辑的EditorGridPanel

    NULL 博文链接:https://zxf-noimp.iteye.com/blog/629629

    EXT核心API详解

    1、Ext类 ………………………………… 2 2、Array类 …………………………… 4 3、Number类 …………………………… 4 4、String类 …………………………… 4 5、Date类 ……………………………… 5 6、Function类 ...

    Ext组件描述,各个组件含义

    **2.5 Editor Grid Panel (Ext.grid.EditorGridPanel)** - **xtype**: `editorgrid` - **功能描述**:Editor Grid Panel 是一个支持行级编辑的网格面板。 - **主要用途**:适合于需要对表格中的数据进行编辑的场景...

    Extjs EditorGridPanel中ComboBox列的显示问题

    为了解决这个问题需要在EditorGridPanel的ColumnModel中显示ComboBox的地方使用renderer属性,重新渲染,方法如下: 代码如下: //部门列表 var comboxDepartmentStore = new Ext.data.Store({ proxy: new Ext.data....

    Ext表格控件和树控件

    ### Ext表格控件和树...通过以上内容,我们可以看到 `GridPanel`、`EditorGridPanel` 和 `TreePanel` 在 Ext JS 中的应用非常广泛,它们提供了强大的数据展示和编辑能力,同时也为开发者提供了高度的灵活性和定制性。

    Ext grid合并单元格

    根据提供的文件信息,我们可以深入探讨如何在 Ext JS 中实现 Grid 的单元格合并功能。此案例主要涉及到了自定义 GridView 的 `renderHeaders` 方法来达到单元格合并的目的,并且还涉及了模板(Template)的使用、...

    treePanel与gridPanel技术实现页面的增删改查

    在本文中,我们将深入探讨`treePanel`和`gridPanel`技术在页面上实现数据的增删改查功能。这两个组件是Ext JS框架中的核心组件,广泛用于构建数据驱动的用户界面。`treePanel`主要用于展示层级结构的数据,如文件...

Global site tag (gtag.js) - Google Analytics