欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

初次maven实现学生信息系统

程序员文章站 2022-05-06 12:39:30
...

一、实现要求:
实训课题
目标:实现一个简单的学生信息系统,主要有学习信息管理和学生成绩管理功能。
实现方式:上机操作。
具体要求:请仔细阅读下方要求
语言方向
Java 1、后端采用javaEEWeb架构,springMVC或者jsp+servlet或者SSH均可
2、 开发工具:eclipse,禁止使用其他开发工具
3、 数据库:mysql
4、 页面排版整洁有序

1、项目名称:StudentManage
2、数据库命名与项目命名一致
1、系统需求
实现一个简单的学生信息系统。主要实现学生信息管理、学生成绩管理功能。
2、主要的数据结构
学生基本信息表 StudentInfo
字段含义 字段名 类型 允许为空 说明
学号 StuID nVarchar(50) No 自动生成,不能重复
姓名 StuName nVarchar(50) No
专业 Profession int No 用下拉列表控件显示,计算机控制、网络安全、计算机应用
入学日期 addDate datetime No 使用日期控件展示
性别 Sex Int NO 使用单选按钮显示,男-1、女-0
身份证号 IDNum nVarchar(20) No 需要验证身份证号码是否正确
总学分 TotalScore Int No 根据总成绩的10%计算
其他说明 Note nvarchar(100) Yes

学生成绩信息表 StuMarkInfo
字段含义 字段名 类型 允许为空 说明
成绩编号 Markid nVarchar(50) No 自动生成,不能重复
学号 StuID nVarchar(50) No 用下拉列表控件显示所有学生,菜单展示学生姓名,存入学号值
课程名称 Coursename nVarchar(50) No
平时成绩 baseScore Numeric(18,2) No 必须大于0
考核成绩 testscore Numeric(18,2) No 必须大于0
最终成绩 FinalScore Numeric(18,2) NO 由平时成绩的40%+实验成绩的60%计算得出
添加日期 AddDate Datetime No 默认当前日期时间
其他说明 Note nvarchar(100) Yes

3、功能描述
具体要求
1、在数据库中按照以上的数据表结构要求,创建相应的数据表
2、需要的页面分别是:学生信息的新增、修改和展示页面,学生成绩的新增和展示页面
3、所有必须采用miniUI,包括弹出框,提示信息等
4、新增、修改页面采用4列布局,页面整齐,没有滚动条出现
首页
首页采用左侧菜单,右侧Iframe实现,点击菜单显示列表
菜单分为:学生管理、成绩管理

学生基本信息管理
学生基本信息管理,分为新增,修改和展示页面。
1、展示页面
A、顶部显示“添加学生”按钮,点击后在新窗口中打开添加页面。
B、展示所有的学生信息,可以根据“姓名、专业”等查询条件来进行查询,姓名模糊查询,专业需使用下拉菜单实现。
C、显示列名:序号—姓名—性别—入学日期—年龄—操作,最后一列操作显示编辑和删除的按钮,点击删除按钮,直接删除该条信息;点击编辑按钮,将弹出信息修改页面,可以对学生信息进行编辑。注意:年龄需根据身份证号取得出生日期后计算。
2、新增页面
A、新增页面能够新增姓名、入学日期、专业、性别、身份证号、其他说明等信息
B、入学日期使用日期控件进行选择,无需获取时分秒。
C、点击保存后关闭新增页面刷新列表

3、修改页面
A、修改页面仅显示“保存修改”按钮。
B、打开修改页面,页面要初始化该条记录的学生名称、入学日期、专业、性别、身份证号、其他说明等信息,仅可修改学生专业,其他不可以修改
C、点击保存修改按钮后,需要保存修改内容,并且关闭用户修改页面。

学生成绩管理
1、实现学生成绩管理,包括成绩记录的新增、删除功能。
2、学生成绩管理的列表页面
A、顶部显示“添加成绩”按钮,点击后在新窗口中打开成绩记录的添加页面
B、展示所有的学生成绩记录,可以根据“添加日期、姓名”来进行模糊查询。列表按添加日期倒排序
C、显示数据列有“序号、姓名、课程名称、平时成绩、考核成绩、最终成绩、其他说明”。最后一列显示删除按钮,点击删除按钮,直接删除该条记录信息
3、学生成绩新增记录页面
A、新增页面能够选择学生,填写课程名称、平时成绩、考核成绩、使用前台JS计算出最终成绩并且可以正确显示到页面最终成绩中。
B、学生选择使用下拉列表展示,绑定所有学号(值属性)和姓名(文本属性),存入数据库时使用学生编号
C、能够根据平时成绩和考核成绩,正确计算出最终成绩并保存到后台。最终成绩由平时成绩的40%+实验成绩的60%计算得出。
D、添加完记录后,需要更新对应学生的总学分,例如:张三的最终成绩是60分,那么总学分就是6学分。总学分=原有学分 + 最终成绩/10。

二、具体实现
数据库:MySql(建表)
初次maven实现学生信息系统
我使用的eclipse建的项目。先用新建maven项目

初次maven实现学生信息系统

先配置web.xml文件,可以去tomcat/conf/目录下的web.xml中copy
初次maven实现学生信息系统

pom.xml中配置maven的依赖,需要什么加什么,资源从网上找
初次maven实现学生信息系统

还有tomcat和maven插件
初次maven实现学生信息系统

前端我用了miniui,只需要去miniui的官网下载(传送门)。下载好是一个java工程,找到WebContent目录下的scripts和res(可能会用的图片)目录,复制转帖到自己工程的webapp目录下,效果图
初次maven实现学生信息系统

第一次写项目,弄清层次搞了好久。最后简陋地分了一下层
初次maven实现学生信息系统

废话不多说,上码:
JDBC代码

package com.epoint.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.epoint.entities.Student;
import com.epoint.utils.GetList;


public class StudentDao {
    String Driver="com.mysql.jdbc.Driver";
    String URL="jdbc:mysql://localhost:3306/sys?useUnicode=true&characterEncoding=utf-8&useSSL=false";
    String username="root";
    String password="Gepoint";
    public Connection getConnection() {
        Connection con=null;
        try {
            Class.forName(Driver);
            con=DriverManager.getConnection(URL, username, password);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        return con;
    }

    public boolean add(Student s) {
        boolean b=false;
        Connection con=getConnection();
        PreparedStatement pst=null;
        try {
            pst = con.prepareStatement("insert into studentinfo values(?,?,?,?,?,?,?,?)");
            pst.setString(1, s.getStuId());
            pst.setString(2, s.getStuName());
            pst.setInt(3, s.getProfession());
            pst.setDate(4, new Date(s.getAddDate().getTime()));
            pst.setInt(5, s.getSex());
            pst.setString(6, s.getIdNum());
            pst.setInt(7, s.getTotalScore());
            pst.setString(8, s.getNote());
            if(pst.execute()) {
                b=true;
            }
        }catch (Exception e) {
            // TODO: handle exception
        }
            finally {
            try {
                if(pst!=null&&!pst.isClosed()) {
                    pst.close();
                }
                if(con!=null&&!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return b;
    }

    public boolean edit(Student s) {
        boolean b=false;
        Connection con=getConnection();
        PreparedStatement pst=null;
        try {
            pst = con.prepareStatement("update studentinfo set StuName=?,Profession=?,addDate=?,Sex=?,IDNum=?,TotalScore=?,Note=? where StuID=?");
            pst.setString(1, s.getStuName());
            pst.setInt(2, s.getProfession());
            pst.setDate(3, new Date(s.getAddDate().getTime()));
            pst.setInt(4, s.getSex());
            pst.setString(5, s.getIdNum());
            pst.setInt(6, s.getTotalScore());
            pst.setString(7, s.getNote());
            pst.setString(8, s.getStuId());
            if(pst.execute()) {
                b=true;
            }
        }catch (Exception e) {
            // TODO: handle exception
        }
            finally {
            try {
                if(pst!=null&&!pst.isClosed()) {
                    pst.close();
                }
                if(con!=null&&!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return b;
    }
    public boolean remove(Student s) {
        boolean b=false;
        Connection con=getConnection();
        PreparedStatement pst=null;
        try {
            pst = con.prepareStatement("DELETE FROM studentinfo WHERE StuID = ?");
            pst.setString(1, s.getStuId());
            if(pst.execute()) {
                b=true;
            }
        }catch (Exception e) {
            // TODO: handle exception
        }
            finally {
            try {
                if(pst!=null&&!pst.isClosed()) {
                    pst.close();
                }
                if(con!=null&&!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return b;
    }
    public int getcount() {
        int i=0;
        Connection con=getConnection();
        PreparedStatement pst=null;
        ResultSet rs=null;
        try {
            pst = con.prepareStatement("select count(*) from studentinfo");
            rs=pst.executeQuery();
            while (rs.next()) {
                i=rs.getInt(1);
            }
        }catch (Exception e) {
            // TODO: handle exception
        }
            finally {
            try {
                if(rs!=null&&!rs.isClosed()) {
                    rs.close();
                }
                if(pst!=null&&!pst.isClosed()) {
                    pst.close();
                }
                if(con!=null&&!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return i;
    }
    public List findA(int pageIndex,int pageSize) {
        List list=new ArrayList();
        Connection con=getConnection();
        PreparedStatement pst=null;
        ResultSet rs=null;
        try {
            pst = con.prepareStatement("select * from studentinfo");
            rs=pst.executeQuery();
            list=new GetList().getList(rs);
        }catch (Exception e) {
            // TODO: handle exception
        }
            finally {
            try {
                if(rs!=null&&!rs.isClosed()) {
                    rs.close();
                }
                if(pst!=null&&!pst.isClosed()) {
                    pst.close();
                }
                if(con!=null&&!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return list;
    }

    public List findS(String stuName) {
        List list=new ArrayList();
        Connection con=getConnection();
        PreparedStatement pst=null;
        ResultSet rs=null;
        try {
            pst = con.prepareStatement("select * from studentinfo where StuName like ?");
            pst.setString(1, "%"+stuName+"%");
            rs=pst.executeQuery();
            list=new GetList().getList(rs);
        }catch (Exception e) {
            // TODO: handle exception
        }
            finally {
            try {
                if(rs!=null&&!rs.isClosed()) {
                    rs.close();
                }
                if(pst!=null&&!pst.isClosed()) {
                    pst.close();
                }
                if(con!=null&&!con.isClosed()) {
                    con.close();
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        System.out.println(list);//2
        return list;
    }
}

实例Student类

package com.epoint.entities;

import java.util.Date;

public class Student {
    private String stuId;
    private String stuName;
    private int profession;
    private Date addDate;
    private int sex;
    private String idNum;
    private int totalScore;
    private String note;
    public String getStuId() {
        return stuId;
    }
    public void setStuId(String stuId) {
        this.stuId = stuId;
    }
    public String getStuName() {
        return stuName;
    }
    public void setStuName(String stuName) {
        this.stuName = stuName;
    }
    public int getProfession() {
        return profession;
    }
    public void setProfession(int profession) {
        this.profession = profession;
    }
    public Date getAddDate() {
        return addDate;
    }
    public void setAddDate(Date addDate) {
        this.addDate = addDate;
    }
    public int getSex() {
        return sex;
    }
    public void setSex(int sex) {
        this.sex = sex;
    }
    public String getIdNum() {
        return idNum;
    }
    public void setIdNum(String idNum) {
        this.idNum = idNum;
    }
    public int getTotalScore() {
        return totalScore;
    }
    public void setTotalScore(int totalScore) {
        this.totalScore = totalScore;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
}

service类

package com.epoint.service;

import java.util.HashMap;
import java.util.List;

import com.epoint.dao.StudentDao;
import com.epoint.entities.Student;
import com.epoint.utils.*;

import com.alibaba.fastjson.*;

public class StudentSer {
    public int getStudentCount() {
        StudentDao sd=new StudentDao();
        return sd.getcount();
    }

    public String getStudent(int pageIndex,int pageSize) {
        HashMap result =getStudentResult(pageIndex, pageSize);
        return new GetJson().encode(result);
    }

    public HashMap getStudentResult(int pageIndex,int pageSize)  {
        List data = new StudentDao().findA(pageIndex, pageSize);
        int total = new StudentDao().getcount();
        HashMap result = new HashMap();
        result.put("data", data);
        result.put("total", total);
        return result;
    }

    public String searchStudent(String stuName) {
        List result =searchStudentResult(stuName);
        JSONArray jsonArray=JSONArray.parseArray(JSON.toJSONString(result));
        System.out.println(jsonArray);
        String json=jsonArray.toString();
        return json;
    }

    public List searchStudentResult(String stuName)  {
        List data = new StudentDao().findS(stuName);    
        System.out.println(data);//3
        return data;
    }

    public void addStudent(Student s) {
      StudentDao sd=new StudentDao();
      sd.add(s);
    }

    public void editStudent(Student s) {
      StudentDao sd=new StudentDao();
      sd.edit(s);
    }
    public void removeStudent(Student s) {
      StudentDao sd=new StudentDao();
      sd.remove(s);
    }
}

三个工具类
getjson

package com.epoint.utils;

import com.alibaba.fastjson.*;



public class GetJson {
    public static String encode(Object obj) {
        if(obj == null || obj.toString().equals("null")) return null;
        if(obj != null && obj.getClass() == String.class){
            return obj.toString();
        }
        String jsonString = JSON.toJSONStringWithDateFormat(obj, "yyyy-MM-dd HH:mm:ss.SSS");
        return jsonString;
    }
    /*
    public static Object decode(Object str) {
        String json = str == null ? null : str.toString();
        if (StringUtil.isNullOrEmpty(json)) return "";
        JSONDeserializer deserializer = new JSONDeserializer();
        deserializer.use(String.class, new DateTransformer("yyyy-MM-dd'T'HH:mm:ss"));       
        Object obj = deserializer.deserialize(json);
        if(obj != null && obj.getClass() == String.class){
            return decode(obj.toString());
        }       
        return obj;
    }
    */
}

getlist

package com.epoint.utils;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class GetList {  
    public List getList(ResultSet rs)throws SQLException{
        List list=new ArrayList();
        ResultSetMetaData md = rs.getMetaData();
        int i=rs.getMetaData().getColumnCount();
        while(rs.next()) {
            HashMap map =new HashMap();
            for(int j=1;j<=i;j++) {
                map.put(md.getColumnName(j), rs.getObject(j).toString());
            }
            list.add(map);
        }
        return list;
    }

}

Stringutil

package com.epoint.utils;

import java.util.Collection;
import java.util.Iterator;

public class StringUtil {
    public static boolean isNullOrEmpty(Object obj) {   
        return obj == null || "".equals(obj.toString());
    }
    public static String toString(Object obj){
        if(obj == null) return "null";
        return obj.toString();
    }
    public static String join(Collection s, String delimiter) {
        StringBuffer buffer = new StringBuffer();
        Iterator iter = s.iterator();
        while (iter.hasNext()) {
            buffer.append(iter.next());
            if (iter.hasNext()) {
                buffer.append(delimiter);
            }
        }
        return buffer.toString();
    }

}

四个servlet类
增加和编辑servlet

package student;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

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 com.epoint.entities.Student;
import com.epoint.service.StudentSer;

import com.alibaba.fastjson.*;


@WebServlet("/studentaddservlet")
public class StudentAddServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public StudentAddServlet() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8"); 
        response.setCharacterEncoding("utf-8"); 
        response.setContentType("text/html;charset=utf-8"); 
        String json=request.getParameter("sjson");
        Student s=new Student();
        JSONArray jsonArray=JSONArray.parseArray(JSON.toJSONString(json));
        JSONObject a=jsonArray.getJSONObject(0);
        int i=0;
        if(a.getString("stuId").equals("")) {
            s.setStuId(UUID.randomUUID().toString().replaceAll("-", ""));
        }else {
            i=1;
            s.setStuId(a.getString("stuId"));
        }
        s.setStuName(a.getString("stuName"));
        s.setProfession(a.getInteger("profession"));
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = format.parse(a.getString("addDate"));
            s.setAddDate(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        s.setSex(a.getInteger("sex"));
        s.setIdNum(a.getString("idNum"));

        s.setTotalScore(0);
        s.setNote(a.getString("note"));
        if(i==0) {
            StudentSer ss=new StudentSer();
            ss.addStudent(s);

        }else {
            StudentSer ss=new StudentSer();
            ss.editStudent(s);
        }
    }
}

表单显示servlet

package student; 

import java.io.IOException;
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 com.epoint.service.StudentSer;


@WebServlet("/studentinfoservlet")
public class StudentInfoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public StudentInfoServlet() {
        super();

    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8"); 
        response.setCharacterEncoding("utf-8"); 
        response.setContentType("text/html;charset=utf-8");
        int pageIndex =Integer.parseInt(request.getParameter("pageIndex"));
        int pageSize =Integer.parseInt(request.getParameter("pageSize"));
        String json = new StudentSer().getStudent(pageIndex, pageSize);
        response.getWriter().write(json);
    }
}

删除servlet

package student;

import java.io.IOException;

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 com.epoint.entities.Student;
import com.epoint.service.StudentSer;
@WebServlet("/studentremoveservlet")
public class StudentRemoveServlet  extends HttpServlet{
    private static final long serialVersionUID = 1L;


    public StudentRemoveServlet() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8"); 
        response.setCharacterEncoding("utf-8"); 
        response.setContentType("text/html;charset=utf-8"); 
        String idStr =request.getParameter("json");   //json为Ajax中的data:{json:row.stuid}
        if (idStr==null) return;
        Student s=new Student();
        String[] ids = idStr.split(",");
        for (int i = 0, l = ids.length; i < l; i++)
        {
            String id = ids[i];
            s.setStuId(id);
            StudentSer ss=new StudentSer();;
            ss.removeStudent(s);         //数据库删除对应的记录
        }
    }
}

搜索servlet

package student;

import java.io.IOException;

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 com.epoint.service.StudentSer;
@WebServlet("/studentsearchservlet")
public class StudentSearchServlet  extends HttpServlet{
    private static final long serialVersionUID = 1L;


    public StudentSearchServlet() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8"); 
        response.setCharacterEncoding("utf-8"); 
        response.setContentType("text/html;charset=utf-8"); 
        String key =request.getParameter("key");
        System.out.println(key);//11
        String json = new StudentSer().searchStudent(key);
        System.out.println(json);
        response.getWriter().write(json);
    }
}

前端代码
datagrid

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>表格</title>

<script src="../scripts/boot.js" type="text/javascript"></script>


</head>
<body>
    <div style="padding-bottom:5px;">

               <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                        <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>       
                    </td>
                    <td style="white-space:nowrap;">
                        <input id="key" class="mini-textbox" emptyText="请输入姓名" style="width:150px;" onenter="onKeyEnter"/>   
                        <a class="mini-button" onclick="search()">查询</a>
                    </td>
                </tr>
            </table>           
        </div> 
    </div>

<div id="datagrid1" class="mini-datagrid"  
    url="../studentinfoservlet" multiSelect="true"
    idField="id" allowResize="true" 
     title="学生信息">
    <div property="columns">
        <div type="checkcolumn" ></div> 
        <div type="indexcolumn" ></div>
        <div field="StuName" width="120" headerAlign="center" align="center">学生姓名</div>    
        <div field="Profession" width="120" headerAlign="center" renderer="onGenderRenderer1" align="center">专业</div>                            
        <div field="addDate" width="100" headerAlign="center" dateFormat="yyyy-MM-dd" align="center">创建日期</div>
        <div field="Sex" width="100" headerAlign="center" renderer="onGenderRenderer" align="center">性别</div>                                
        <div field="IDNum" width="100"   headerAlign="center" align="center">身份证号</div>
        <div field="totalScore" width="100" headerAlign="center" align="center">总学分</div>  
        <div field="Note" width="100" headerAlign="center" align="center">其他</div>    
        <div name="action" width="100" headerAlign="center" renderer="draw" align="center">操作</div>             
    </div>
</div>

    <script type="text/javascript">
    //初始化miniui
    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load();

    function add() {

        mini.open({
            targetWindow: window,
            url: bootPATH + "../studentinfo/studentinfoadd.html",
            title: "新增学生", width: 530, height: 400,
            allowDrag:false,
            onload: function () {
                /*
                //父窗口向子窗口传值;
                var iframe = this.getIFrameEl();
                var data = { action: "new" };
                iframe.contentWindow.SetData(data);
               */
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }


    function draw(e) {
        var grid = e.sender;
        var record = e.record;
        var uid = record.id;
        var rowIndex = e.rowIndex;
        var s="<a class='mini-button' onclick='edit()' style='width:50px;height:20px;padding-top:5px;'>修改</a><a class='mini-button' onclick='removeline()' style='width:50px;height:20px;margin-left:5px;padding-top:5px;'>删除</a> ";
        return s;
    }

    function removeline(){
        var row = grid.getSelected();
        if(row){
            if (mini.confirm("确定删除该行记录?")) {
                var id = row.StuID;
                grid.loading("操作中,请稍后......");
                $.ajax({
                    url: '../studentremoveservlet',
                    data:{json:id},
                    type:'post',
                    success: function (text) {
                        grid.reload();
                    },
                    error: function () {
                    }
                });
            }
        }

    }

    function edit() {

         var row = grid.getSelected();
         if (row) {
             mini.open({
                 url: "studentinfoedit.html",
                 title: "编辑学生", width: 530, height: 400,
                 onload: function () {
                     var iframe = this.getIFrameEl();
                     var data = { action: "edit", id: row.StuID, name: row.StuName, profession: row.Profession, sex:row.Sex, ts:row.TotalScore, note:row.Note, addDate:row.addDate, idNum:row.IDNum};
                     iframe.contentWindow.SetData(data); 
                 },
                 ondestroy: function (action) {
                     grid.reload();

                 }
             });

         } else {
             alert("请选中一条记录");
         }


    }
    function remove() {

        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            if (mini.confirm("确定删除选中记录?")) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    var r = rows[i];
                    ids.push(r.StuID);
                }
                var id = ids.join(',');
                grid.loading("操作中,请稍后......");
                $.ajax({
                    url: '../studentremoveservlet',
                    data:{json:id},
                    type:'post',
                    success: function (text) {
                        grid.reload();
                    },
                    error: function () {
                    }
                });
            }
        } else {
            mini.alert("请选中一条记录");
        }

    }
    function search() {
        var key = mini.get("key").getValue();
        grid.setUrl("../studentsearchservlet");
        grid.load({key:key});
    }
    function onKeyEnter(e) {
        search();
    }
    //JS函数绑定输出格式
    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd');
        return "";
    }
    var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];        
    function onGenderRenderer(e) {
        for (var i = 0, l = Genders.length; i < l; i++) {
            var g = Genders[i];
            if (g.id == e.value) return g.text;
        }
        return "";
    }
    var Genders1 = [{ id: 1, text: '物联网' }, { id: 2, text: '软件工程'}, { id: 3, text: '计算机科学'}];        
    function onGenderRenderer1(e) {
        for (var i = 0, l = Genders1.length; i < l; i++) {
            var g = Genders1[i];
            if (g.id == e.value) return g.text;
        }
        return "";
    }
    </script>
</body>
</html>

添加页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>学生增加</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<script src="../scripts/boot.js" type="text/javascript"></script>


<style type="text/css">
html, body {
    padding: 0;
    margin: 0;
    border: 0;
    height: 100%;
    overflow: hidden;
}
</style>
</head>
<body>

    <form id="form1" method="post"
        style="margin-left: 15px; margin-right: 15px;">
        <input name="stuId" class="mini-hidden" />
        <div style="padding-left: 11px; padding-bottom: 5px;">
            <table style="table-layout: fixed;">
                <tr style="height: 50px">
                    <td style="width: 80px;">姓名:</td>
                    <td style="width: 150px;"><input name="stuName"
                        class="mini-textbox" required="true" emptyText="请输入姓名" /></td>
                    <td style="width: 80px;">专业:</td>
                    <td style="width: 150px;"><input name="profession"
                        id="profession" class="mini-combobox" valueField="professionId"
                        textField="professionName" url="Data/profession.txt"
                        required="true" emptyText="请选择专业" /></td>
                </tr>
                <tr style="height: 50px">
                    <td>入学日期:</td>
                    <td><input name="addDate" class="mini-datepicker"
                        required="true" emptyText="请选择日期" /></td>
                    <td>性别:</td>
                    <td>
                        <div name="sex" class="mini-radiobuttonlist" repeatItems="2"
                            repeatLayout="table" repeatDirection="vertical" textField="sexName"
                            valueField="sexId" value="cn" url="Data/sex.txt"></div></td>
                </tr>

                <tr style="height: 50px">
                    <td>身份证号:</td>
                    <td><input name="idNum" class="mini-textbox" required="true"
                        emptyText="请输入身份证号" /></td>
                </tr>
                <tr style="height: 130px">
                    <td>其他:</td>
                    <td colspan="3"><input name="note" class="mini-textarea"
                        style="width: 386px; height: 100px;" /></td>
                </tr>
                <tr style="height: 50px">
                    <td colspan="4">
                        <div style="text-align: center; padding: 10px;">
                            <a class="mini-button" onclick="onOk"
                                style="width: 60px; margin-right: 20px;">确定</a> <a
                                class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("form1");

        function SaveData() {
            var o = form.getData();

            form.validate();
            if (form.isValid() == false)
                return;

            var json = mini.encode([ o ]);
            $.ajax({
                url : "../studentaddservlet",
                type : 'post',
                data : {
                    sjson : json
                },
                cache : false,
                success : function(text) {
                    mini.alert("保存成功", "提示", function() {
                        CloseWindow();
                    });
                },
                error : function(jqXHR, textStatus, errorThrown) {
                    mini.alert(json, "提示", function() {
                        CloseWindow();
                    });
                }
            });
        }
        function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象,克隆后才可以安全使用
                data = mini.clone(data);

                $.ajax({
                    url : "../data/AjaxService.jsp?method=GetEmployee&id="
                            + data.id,
                    cache : false,
                    success : function(text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);

                        //onDeptChanged();
                        //mini.getbyName("position").setValue(o.position);
                    }
                });
            }
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了,是否先保存?")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow)
                return window.CloseOwnerWindow(action);
            else
                window.close();
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
</body>
</html>

修改页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>学生增加</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

    <script src="../scripts/boot.js" type="text/javascript"></script>


    <style type="text/css">
    html, body
    {        
        padding:0;
        margin:0;
        border:0;
        height:100%;
        overflow:hidden;
    }
    </style>
</head>
<body>    

    <form id="form1" method="post" style="margin-left:15px;margin-right:15px;">
        <input name="id" class="mini-hidden" />
        <div style="padding-left:11px;padding-bottom:5px;">
            <table style="table-layout:fixed;">
                <tr style="height:50px">
                    <td style="width:80px;">姓名:</td>
                    <td style="width:150px;">    
                        <input name="stuName" class="mini-textbox" required="true"  emptyText="请输入姓名"/>
                        <input name="stuId" class="mini-textbox" style="display:none" />
                    </td>
                    <td style="width:80px;">专业:</td>
                    <td style="width:150px;">    
                        <input name="profession" id="profession" class="mini-combobox" valueField="professionId" textField="professionName" 
                            url="Data/profession.txt" required="true" emptyText="请选择专业" />
                    </td>
                </tr>
                <tr style="height:50px">
                    <td >入学日期:</td>
                    <td >    
                        <input name="addDate" class="mini-datepicker"
                        required="true" emptyText="请选择日期" />
                    </td>
                    <td >性别:</td>
                    <td >    
                        <div name="sex" class="mini-radiobuttonlist" repeatItems="2"
                            repeatLayout="table" repeatDirection="vertical" textField="sexName"
                            valueField="sexId" value="cn" url="Data/sex.txt"></div>
                    </td>
                </tr>

                <tr style="height:50px">
                    <td >身份证号:</td>
                    <td >    
                        <input name="idNum" class="mini-textbox" required="true" emptyText="请输入身份证号"  />
                    </td>
                    <td >总学分:</td>
                    <td >    
                        <input name="totalScore" class="mini-textbox" readonly="readonly"  />
                    </td>
                </tr>
                <tr style="height:130px">
                    <td >其他:</td>
                    <td colspan="3">    
                        <input name="note" class="mini-textarea" style="width:386px;height:100px;" />
                    </td>
                </tr>
                <tr style="height:50px">
                    <td colspan="4">
                        <div style="text-align: center; padding: 10px;">
                            <a class="mini-button" onclick="onOk"
                                style="width: 60px; margin-right: 20px;">确定</a> <a
                                class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
                        </div>
                    </td>
                </tr>           
            </table>
        </div>        
    </form>
    <script type="text/javascript">
        mini.parse();
        var form = new mini.Form("form1");



        function SaveData() {
            var o = form.getData(); 
            form.validate();
            if (form.isValid() == false) return;
            var json = mini.encode([o]);
            $.ajax({
                url: "../studentaddservlet",
                type: 'post',
                data: { sjson: json },
                cache: false,
                success: function (text) {
                    mini.alert("修改成功","提示",function(){
                        CloseWindow();
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert("修改失败","提示",function(){
                        CloseWindow();
                    });
                }
            });
        }

        ////////////////////
        //标准方法接口定义
        function SetData(data) {
             if (data.action == "edit") {
                 //跨页面传递的数据对象,克隆后才可以安全使用
                 data = mini.clone(data);
                 var text = mini.decode({stuId:data.id,stuName:data.name,profession:data.profession,addDate:data.addDate, sex:data.sex, idNum:data.idNum, totalScore:data.ts,note:data.note});
                 form.setData(text);
             }
        }


        function CloseWindow(action) {            
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了,是否先保存?")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }

        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
</body>
</html>