bestpay学习 - - 一个轻量级的完全开源项目

NUTZ  一个轻量级的完全开源项目

* 讲义:bestpay

* 讲义创建:2018年6月13日10:49:22

设计背景

随着脚本语言所刮起的开发热潮,Java在Web开发领域逐渐露出疲态,而Java被“脚本小子”诟病最多的便是低下的开发效率。从本质上来说,Java语言本身为程序员提供的帮助只有两点,一是语言的语法,二是内置的类库。

现在从事Web开发,大多是采用第三方的类库(或者说是框架),比如流行的SSH。 所谓Java在Web开发的低效,不妨这样说比较贴切一些:采用第三方类库进行开发比较低效。为此,开发者zozoh开发了这一旨在提高Web开发人员的生产力的Nutz框架。

Nutz可以做什么?

  • Dao:针对JDBC的薄封装,事务模板,无缓存
  • Ioc:JSON 风格的配置文件,声明时切片支持
  • Mvc:注解风格的配置,内置多文件上传功能
  • Json:解析和渲染
  • Castors:Java对象类型转换
  • Lang: 更简洁的Java函数以及更丰富的反射支持
  • Aop: 轻便快速的切面编程支持
  • Plugin:轻便的插件机制
  • Resource:资源扫描

Nutz为谁而设计?

  • 如果你觉得Hibernate控制比较繁琐,iBatis编写SQL又比较麻烦,Nutz.Dao专为你设计。
  • 如果你觉得在多个服务器部署或者修改Spring配置文件很麻烦,Nutz.Ioc专为你设计
  • 如果你觉得直接写XML配置文件很麻烦,可视化编辑器又没控制感,Nutz.Mvc专为你设计
  • 如果你觉得JSON转换很麻烦(要写超过一行以上的代码),Nutz.Json专为你设计
  • 如果你觉得Java语法不如Ruby便捷, Nutz.Castor以及Nutz.Lang专为你设计
  • 如果你以前根本没接触过SSH ,只使用JDBC编程, 整个Nutz专门为你设计

同传统的SSH相比,它所具备的特点:

  • 轻:当前最新版,整个jar文件共950k
  • 薄: 针对JDBC的薄封装,无缓存
  • 全:提供了 Dao (ORM, SQL 管理),Ioc, Aop, Mvc, Json解析等必要功能
  • 活:各个部分可以独立使用,比如在Spring里采用Nutz.Dao ,又比如在Nutz.Ioc里使用 - Hibernate等
  • 整:它所有功能均不依赖第三方jar文件。

简单!!如果一个Web应用,你在WEB-INF/lib下只需要放置一个nutz.jar就够了

活跃的社区,回复非常及时

快速搭建一个管理后台

1. 首先去nutz的github 下载一份源码(这里选择管理后台源码)

这里选择企业级管理平台: https://github.com/Wizzercn/NutzWk,效果图如下

  • 项目介绍
搭建成功后的效果图

搭建的工作量
  • 基于企业级demo,创建一个新的模块,命名长新云(ChangXinYun)
    代码具备如下功能:
    • list列表功能,具备分页,筛选记录,导出
    • 新增(或CRUD)
    • 导入excel




ChangXinYunController.java 代码:

        package cn.wizzer.app.web.modules.controllers.platform.cms;
        import java.io.IOException;
        import java.io.InputStream;
        import java.io.OutputStream;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.text.DecimalFormat;
        import java.util.Date;
        import java.util.HashMap;
        import java.util.LinkedList;
        import java.util.List;
        import java.util.Map;

        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;

        import org.apache.poi.hssf.usermodel.HSSFFont;
        import org.apache.poi.hssf.usermodel.HSSFWorkbook;
        import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
        import org.apache.poi.ss.usermodel.Cell;
        import org.apache.poi.ss.usermodel.CellStyle;
        import org.apache.poi.ss.usermodel.Row;
        import org.apache.poi.ss.usermodel.Sheet;
        import org.apache.poi.xssf.usermodel.XSSFWorkbook;
        import org.apache.shiro.authz.annotation.RequiresAuthentication;
        import org.nutz.dao.Dao;
        import org.nutz.dao.Sqls;
        import org.nutz.dao.entity.Record;
        import org.nutz.dao.sql.Sql;
        import org.nutz.dao.sql.SqlCallback;
        import org.nutz.ioc.loader.annotation.Inject;
        import org.nutz.ioc.loader.annotation.IocBean;
        import org.nutz.lang.Strings;
        import org.nutz.lang.random.R;
        import org.nutz.lang.util.NutMap;
        import org.nutz.log.Log;
        import org.nutz.log.Logs;
        import org.nutz.mvc.adaptor.WhaleAdaptor;
        import org.nutz.mvc.annotation.AdaptBy;
        import org.nutz.mvc.annotation.At;
        import org.nutz.mvc.annotation.Ok;
        import org.nutz.mvc.annotation.POST;
        import org.nutz.mvc.annotation.Param;
        import org.nutz.mvc.impl.AdaptorErrorContext;
        import org.nutz.mvc.upload.TempFile;
        import org.nutz.mvc.upload.UploadAdaptor;

        import com.alibaba.druid.util.StringUtils;
        import com.mysql.jdbc.Connection;

        import cn.wizzer.app.cms.modules.models.ChangXinYunModel;
        import cn.wizzer.app.cms.modules.services.ChangXinYunService;
        import cn.wizzer.app.sys.modules.services.SysMenuService;
        import cn.wizzer.app.web.commons.base.Globals;
        import cn.wizzer.app.web.commons.slog.annotation.SLog;
        import cn.wizzer.app.web.modules.controllers.httputils.HttpClient4;
        import cn.wizzer.framework.base.Result;
        import cn.wizzer.framework.page.datatable.DataTableColumn;
        import cn.wizzer.framework.page.datatable.DataTableOrder;
        import cn.wizzer.framework.util.DateUtil;
        import okhttp3.Request;

        /**
         * Created by William 2018年6月5日09:55:33
         */
        @IocBean
        @At("/platform/changxinyun")
        public class ChangXinYunController {
            @SuppressWarnings("unused")
            private static final Log log = Logs.get();

            @Inject
            private SysMenuService menuService;

            @Inject
            private ChangXinYunService changXinYunService;

            @Inject
            private Dao dao;
            //dao.create(ChangXinYunModel.class, true);

            @At({"", "/index/","/index/?"})
            @Ok("beetl:/changxinyun/index.html")
            @RequiresAuthentication
            public void index(@Param("startDealWithTimeMills") String startDealWithTimeMills,@Param("startDealWithTimeMills") String fromUrl ,HttpServletRequest req) {

                if (!StringUtils.isEmpty(fromUrl))
                    req.setAttribute("startDealWithTimeMills", startDealWithTimeMills);
                else 
                    req.setAttribute("startDealWithTimeMills", "");
            }

            @At
            @Ok("json:full")
            @RequiresAuthentication
            public Object data(@Param("startDealWithTimeMills") String startDealWithTimeMills,@Param("searchKey") String searchKey,@Param("name") String name,@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns,
                    HttpServletRequest req) {
            String whereName = "";
            if (!Strings.isBlank(searchKey)){
                whereName = " and ( t.pid LIKE '%"+searchKey+"%' or t.name like '%"+searchKey+"%' or t.phone like '%"+searchKey+"%') ";
            }

            if (!Strings.isBlank(startDealWithTimeMills)){
                whereName = " and  requestAt > '"+startDealWithTimeMills+"' ";
            }

            String sqlCount ="SELECT t.* from YZF_ChangXinYun t where 1=1 "+whereName+" order by orderBy desc";// WHERE type='0'"+whereName+"ORDER BY isTop DESC"; 
            Sql sql = Sqls.create(sqlCount);

            NutMap re = changXinYunService.data(length, start, draw,sql,sql);

            @SuppressWarnings("rawtypes")
            LinkedList dataList = (LinkedList) re.get("data");

            for (int i=0;i<dataList.size();i++) {

                Record record =  (Record) dataList.get(i);
                //map.keySet()返回的是所有key的值
                //得到每个key多对用value的值
                String str = record.getString("id");
                Sql sqlCount2 = Sqls.create("select count(*) as putScore from YZF_ChangXinYun t where 1=1 "+whereName);// WHERE leaveRoomDate IS NULL and roomId='"+str+"'");

                sqlCount2.setCallback(Sqls.callback.integer());
                int putScore=dao.execute(sqlCount2).getInt();
                record.put("putscore", putScore);

            }

            req.setAttribute("lists", re);
            System.out.println("re:"+re);

            return re;
            }

            @At
            @Ok("beetl:/changxinyun/add.html")
            @RequiresAuthentication
            @AdaptBy(type = WhaleAdaptor.class)
            public void add(HttpServletRequest req) {
            }

            @At
            @Ok("json")
            @SLog(tag = "新建测试", msg = "")
            @AdaptBy(type = WhaleAdaptor.class)
            public Object addDo(@Param("path") String path,@Param("key") String[] key,@Param("value") String[] value,@Param("methodName") String methodName,@Param("..") ChangXinYunModel chxyun,HttpServletRequest req) {
                System.out.println("");
            try {
                Map<String,Object> params = new HashMap<>();
                if (key == null ||value == null) return Result.error("key or value 不能全部为空");

                String name = null,pid = null,phone = null;
                for (int i=0;i<key.length;i++) {
                    if (StringUtils.isEmpty(key[i]) || StringUtils.isEmpty(value[i])) continue;
                    if (key[i].trim().equals("phone") || key[i].trim().equals("pid") || key[i].trim().equals("name")) {
                        if (key[i].trim().equals("phone")) phone = value[i].trim();
                        if (key[i].trim().equals("pid")) pid = value[i].trim();
                        if (key[i].trim().equals("name")) name = value[i].trim();
                        params.put(key[i].trim(), OpenSSLUtil.opensslEncrypt(value[i].trim()));
                    }
                    else 
                        params.put(key[i].trim(), value[i].trim());
                }

                if (!params.containsKey("token")) return Result.error("token 不能为空");
                if (!params.containsKey("type")) return Result.error("type 不能为空");
                if (!params.containsKey("name")) return Result.error("name 不能为空");
                if (!params.containsKey("pid")) return Result.error("pid 不能为空");
                if (!params.containsKey("phone")) return Result.error("phone 不能为空");

                String tokenString = HttpClient4.doPost(path,params);

                doPostChangXinYunModel(name,pid,phone,tokenString);

                    return Result.success("success:"+tokenString,tokenString);          
                } catch (Exception e) {
                    return Result.error("system.error");
                }

            }


            @At
            @Ok("beetl:/changxinyun/importExcel.html")
                @SLog(tag = "新建测试", msg = "")
                @AdaptBy(type = WhaleAdaptor.class)
                public void doImportExcel() {
            }

            @AdaptBy(type = UploadAdaptor.class, args = {"ioc:videoExcel"})
            @POST
            @At
            @Ok("json")
            @RequiresAuthentication
            public Object dealWithExcel(@Param("Filedata") TempFile tf, HttpServletRequest req,HttpServletResponse resp, AdaptorErrorContext err) {

                    int startDealWithTimeMills = Integer.parseInt(System.currentTimeMillis()/1000 + ""); // 开始处理导出数据的时间

                try {
                    if (err != null && err.getAdaptorErr() != null)  return NutMap.NEW().addv("code", 1).addv("msg", "上传文件不合法");
                    if (tf == null) return Result.error("请选择要上传的excel文件");

                        String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                        InputStream in = tf.getInputStream();
                        String suffix = f.substring(f.lastIndexOf("."));

                        if (StringUtils.isEmpty(suffix) || suffix.indexOf("xlsx") == -1)  
                            //2003-2007版本的excel
                            readExcel(in,false);     
                        else 
                             //2010版excel
                            readExcel(in,true);     


                        return Result.success("上传成功", startDealWithTimeMills);

                } catch (Exception e) {
                    if (e instanceof OLE2NotOfficeXmlFileException){
                        return Result.error("请核对2003/2007版本excel后缀名为.xls,2010及以上版本excel后缀名为.xlsx");
                    }
                    e.printStackTrace();
                    return Result.error("导入时错误,系统异常:" +e.getMessage());
                }

            }

            /**
             * 插入数据对象到数据库中
             * @param order
             * @param name
             * @param pid
             * @param phone
             * @return
             */
            private ChangXinYunModel doPostChangXinYunModel(String name,String pid,String phone,String result) throws Exception{
                ChangXinYunModel cxyModel = new ChangXinYunModel();
                    cxyModel.setOrderBy(getLastestOrder());
                    cxyModel.setName(name);
                    cxyModel.setPid(pid);
                    cxyModel.setPhone(phone);
                    StringBuilder sb =  new StringBuilder();
                    sb.append("?");
                    sb.append("name="+name+"&");
                    sb.append("pid="+pid+"&");
                    sb.append("phone="+phone+"&");
                    sb.append("type="+1+"&");
                    String token = "z5yaoljghngtuyrp";
                    sb.append("token="+token);
                    Map<String, Object> paramMap = new HashMap<>();
                    paramMap.put("name", OpenSSLUtil.opensslEncrypt(name));
                    paramMap.put("pid", OpenSSLUtil.opensslEncrypt(pid));
                    paramMap.put("phone", OpenSSLUtil.opensslEncrypt(phone));
                    paramMap.put("token", "xxxxxxxxxx");
                    paramMap.put("type", 1);
                    result = (StringUtils.isEmpty(result)) ? HttpClient4.doPost("https://api.----xxxxx.com/Mxxxxxxxx/query/",paramMap) : result;
                    cxyModel.setToken(token);
                    cxyModel.setOtherInfo("name="+OpenSSLUtil.opensslEncrypt(name)+"&pid="+OpenSSLUtil.opensslEncrypt(pid)+"&phone="+OpenSSLUtil.opensslEncrypt(phone));
                    cxyModel.setMethodName("POST");
                    cxyModel.setOpAt(Integer.parseInt(System.currentTimeMillis()/1000+""));
                    cxyModel.setPath(sb.toString());
                    cxyModel.setRequestAt(""+System.currentTimeMillis());
                    cxyModel.setResult(result);
                    cxyModel.setDelFlag(false);
                    cxyModel.setBank_card("");
                    cxyModel.setComment("三要素认证");
                    cxyModel.setHead("");
                    cxyModel.setPhone(phone);
                    cxyModel.setPid(pid);
                    dao.insert(cxyModel);
                return cxyModel;
            }

            /**
             * 获取最后一个排序顺序
             * 
             * @return
             */
            private int getLastestOrder() {
                 Sql sql = Sqls.create("SELECT orderBy FROM YZF_ChangXinYun order by orderBy desc limit 0,1");
                //这里可以写成只查询一个常见8种类型,例如String sql.setCallback(Sqls.callback.entities());
                sql.setCallback(new SqlCallback() {
                    @Override
                    public Object invoke(java.sql.Connection conn, ResultSet rs, Sql sql) throws SQLException {
                         List<String> list = new LinkedList<String>();
                        while (rs.next())
                            list.add(rs.getString("orderBy"));
                        return list;
                    }
                });
                dao.execute(sql);
                List<String> list = sql.getList(String.class);
                return (list == null || list.isEmpty()) ? 1 :(int)Double.parseDouble(list.get(0)) + 1;
                }

            /**
             * 插入数据对象到数据库中
             * @param order
             * @param name
             * @param pid
             * @param phone
             * @return
             * @deprecated
             */
            private ChangXinYunModel doGetChangXinYunModel(int order,String name,String pid,String phone) {
                ChangXinYunModel cxyModel = new ChangXinYunModel();
                    cxyModel.setOrderBy(order);
                    cxyModel.setName(name);
                    cxyModel.setPid(pid);
                    cxyModel.setPhone(phone);
                    StringBuilder sb =  new StringBuilder();
                    sb.append("https://api.--xxxx.com/xxxxxxx/query?");
                    sb.append("name="+name+"&");
                    sb.append("pid="+pid+"&");
                    sb.append("phone="+phone+"&");
                    sb.append("type="+1+"&");
                    String token = "xxxxxxxxxxxxxx";
                    sb.append("token="+token);
                    String result = HttpClient4.doGet(sb.toString());
                    cxyModel.setToken(token);
                    cxyModel.setMethodName("GET");
                    cxyModel.setOpAt(Integer.parseInt(System.currentTimeMillis()/1000+""));
                    cxyModel.setPath(sb.toString());
                    cxyModel.setRequestAt(""+System.currentTimeMillis());
                    cxyModel.setResult(result);
                    cxyModel.setDelFlag(false);
                    cxyModel.setBank_card("");
                    cxyModel.setComment("三要素认证");
                    cxyModel.setHead("");
                    cxyModel.setOtherInfo("");
                    cxyModel.setPhone(phone);
                    cxyModel.setPid(pid);
                    dao.insert(cxyModel);
                return cxyModel;
            }

            @SuppressWarnings("deprecation")
                private String getValue(Cell cell) {
                if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN)
                    return String.valueOf(cell.getBooleanCellValue()); // 返回布尔类型的值 
                else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                     DecimalFormat df = new DecimalFormat("0");
                     String val = df.format(cell.getNumericCellValue());        
                    return val; // 返回数值类型的值 
                }
                else 
                    return String.valueOf(cell.getStringCellValue());  // 返回字符串类型的值 
            }

            @SuppressWarnings("resource")
            private void readExcel(InputStream in,boolean is2010) throws Exception {
                InputStream is = in;
                org.apache.poi.ss.usermodel.Workbook workBook = null;
                if (is2010)
                    workBook = new XSSFWorkbook(is); //2010
                else 
                    workBook = new HSSFWorkbook(is); //2003-2007

                if (workBook.getNumberOfSheets() < 1) throw new RuntimeException("excel没有表格存在");

                // 循环工作表Sheet
                for (int numSheet = 0; numSheet < workBook.getNumberOfSheets(); numSheet++) {
                    Sheet sheet = workBook.getSheetAt(numSheet);
                    if (sheet == null) {
                        continue;
                    }

                    //校验表头  序号 姓名 身份证 手机号
                    if (sheet.getLastRowNum() < 1) continue;
                    Row headRow = sheet.getRow(0);

                    if (headRow.getCell(0) == null || StringUtils.isEmpty(getValue(headRow.getCell(0))) || !getValue(headRow.getCell(0)).trim().equals("序号")) throw new RuntimeException("表头第一列必须为[序号]");
                    if (headRow.getCell(1) == null || StringUtils.isEmpty(getValue(headRow.getCell(1))) || !getValue(headRow.getCell(1)).trim().equals("姓名")) throw new RuntimeException("表头第一列必须为[姓名]");
                    if (headRow.getCell(2) == null || StringUtils.isEmpty(getValue(headRow.getCell(2))) || !getValue(headRow.getCell(2)).trim().equals("身份证")) throw new RuntimeException("表头第一列必须为[身份证]");
                    if (headRow.getCell(3) == null || StringUtils.isEmpty(getValue(headRow.getCell(3))) || !getValue(headRow.getCell(3)).trim().equals("手机号")) throw new RuntimeException("表头第一列必须为[手机号]");

                    //校验表格数据必须大于1条
                    if (sheet.getLastRowNum() < 2) throw new RuntimeException(sheet.getSheetName() + ",没有需要导入的数据");

                    // 循环行Row
                    for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
                        Row row = sheet.getRow(rowNum);
                        if (row == null) {
                            continue;
                        }

                        if (rowNum == 100) Thread.sleep(1000);

                        if (row.getCell(1) == null || StringUtils.isEmpty(getValue(row.getCell(1)))) continue;
                        if (row.getCell(2) == null || StringUtils.isEmpty(getValue(row.getCell(2)))) continue;
                        if (row.getCell(3) == null || StringUtils.isEmpty(getValue(row.getCell(3)))) continue;
                        //init Model
                        doPostChangXinYunModel(getValue(row.getCell(1)), getValue(row.getCell(2)), getValue(row.getCell(3)),null);
                    }
                }
            }

            private HttpServletRequest getTeamInfo(HttpServletRequest req ,String sql) {
                req.setAttribute("teams", changXinYunService.list(Sqls.create(sql)));
                return req;
            }

            @SuppressWarnings({ "unchecked", "deprecation" })
            @At("/export")
            @Ok("void") // 加了之后不走RouteFilter,否则响应输出流出错
            @SLog(tag = "导出长新云", msg = "ID:${args[2].getAttribute('id')}")
            public void export(HttpServletRequest req, HttpServletResponse resp) {
                String searchKey = (String) req.getParameter("searchKey");

                OutputStream out = null;
                    HSSFWorkbook workbook=null;

                    try {
                        out = resp.getOutputStream();

                        // poi
                        resp.addHeader("content-type", "applicationnd.ms-excel;charset=utf-8");
                        resp.addHeader("content-disposition", "attachment; filename=ChangXinYun"+DateUtil.format(new Date(), "yyyyMMddHHmmss")+".xls"); 
                        //          Workbook workBook = Excel.createWorkbook(Excel.Excel_Type.EXCEL_97_2003);
                        //HSSFWorkbook workbook = new HSSFWorkbook();
                         workbook = new HSSFWorkbook();

                        Sheet sheet = workbook.createSheet("长新云数据");

                        String whereName = "";
                    if (!Strings.isBlank(searchKey)){
                        whereName = " and ( t.pid LIKE '%"+searchKey+"%' or t.name like '%"+searchKey+"%' or t.phone like '%"+searchKey+"%') ";
                    }

                    String sql ="SELECT t.* from YZF_ChangXinYun t where 1=1 "+whereName+" order by orderBy ";// WHERE type='0'"+whereName+"ORDER BY isTop DESC";

                        req = getTeamInfo(req,sql + " asc");
                        Row row = sheet.createRow(0);

                        HSSFFont font  = workbook.createFont();
                        font.setFontName("微软雅黑");
                        font.setFontHeightInPoints((short) 11);//设置字体大小
                        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示

                        CellStyle headStyle = workbook.createCellStyle();
                        headStyle.setAlignment(CellStyle.ALIGN_CENTER);
                        headStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
                        headStyle.setBorderRight(CellStyle.BORDER_THIN);
                        headStyle.setFont(font);
                        //SELECT t.*,l.matchName as matchname from game_team t left join game_matchmain l on t.leagueId=l.id 
                        Cell head0 = row.createCell(0);
                        head0.setCellValue("序号");
                        head0.setCellStyle(headStyle);
                        Cell head1 = row.createCell(1);
                        head1.setCellValue("姓名");
                        head1.setCellStyle(headStyle);
                        Cell head2 = row.createCell(2);
                        head2.setCellValue("身份证");
                        head2.setCellStyle(headStyle);
                        Cell head3 = row.createCell(3);
                        head3.setCellValue("手机号");
                        head3.setCellStyle(headStyle);
                        Cell head4 = row.createCell(4);
                        head4.setCellValue("查询类型");
                        head4.setCellStyle(headStyle);
                        Cell head5 = row.createCell(5);
                        head5.setCellValue("结果");
                        head5.setCellStyle(headStyle);

                        List<Record> records = (List<Record>) req.getAttribute("teams");
                        for (int i = 0; i < records.size(); i++) {
                            Row r = sheet.createRow(i + 1);
                            r.createCell(0).setCellValue(records.get(i).getString("orderby"));
                            r.createCell(1).setCellValue(records.get(i).getString("name"));
                            r.createCell(2).setCellValue(records.get(i).getString("pid"));
                            r.createCell(3).setCellValue(records.get(i).getString("phone"));
                            r.createCell(4).setCellValue("实名认证");
                            r.createCell(5).setCellValue(records.get(i).getString("result"));
                        }

                sheet.autoSizeColumn((short)0); //调整第一列宽度
                sheet.autoSizeColumn((short)1); //调整第二列宽度
                sheet.autoSizeColumn((short)2); //调整第三列宽度
                sheet.autoSizeColumn((short)3); //调整第四列宽度
                sheet.autoSizeColumn((short)4); //调整第五列宽度
                sheet.autoSizeColumn((short)5); //调整第六列宽度

                        workbook.write(out);    // 输出
                        out.flush();
                    } catch (Exception e) {
                        System.out.println("**************队伍信息导出为EXCEL发生错误");
                        e.printStackTrace();
                    } finally {
                        try {
                            workbook.close();
                            out.close();
                        } catch (IOException e) 
                        {
                            e.printStackTrace();
                        }
                    }
            }

        }




首页index.html 代码

    <% layout("/layouts/platform.html"){ %>
    <header class="header navbar bg-white shadow">
        <div class="btn-group tool-button">
            <a class="btn btn-primary navbar-btn" href="${base}/platform/changxinyun/add"
                data-pjax><i class="ti-plus"></i>新建测试</a>
        </div>
        <div class="btn-group tool-button">
            <a class="btn btn-primary navbar-btn" onclick="exportData(this)" href="javascript:void(0);"
                data-pjax>导出Excel数据</a>
        </div>
        <div class="pull-right offscreen-right">
            <button class="btn btn-primary navbar-btn"
                onclick="sublime.toggleFilter('.cd-panel')">
                <i class="fa fa-sliders"></i> 筛选
            </button>
        </div>
    </header>
    <div class="content-wrap">
        <div class="wrapper" style="min-height: 500px; overflow-x: scroll">
            <div class="row mb15">
                <div class="col-lg-12">

                    <table id="treeTable"
                        class="table table-bordered table-striped mg-t datatable">
                        <thead>
                            <tr>
                                <th class="col-md-2" style="width:50px;">序号</th>
                                <th class="col-md-2"  style="width:50px;">姓名</th>
                                <th class="col-md-2" style="width:50px;">身份证</th>
                                <th class="col-md-2" style="width:50px;">手机号</th>
                                <th class="col-md-2"  style="width:50px;">查询类型</th>
                                <th class="col-md-1"  style="width:350px;">结果</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="cd-panel from-right">
        <header class="cd-panel-header">
            <h4>高级筛选</h4>
        </header>
        <div class="cd-panel-container">
            <div class="cd-panel-content shadow">
                <div class="form-group">
                    <label for="title">查询手机号码/姓名/身份证</label> 
                    <input type="text" id="searchKey" name="searchKey" class="form-control" placeholder="手机号码/姓名/身份证" autofocus>
                </div>
                <button id="searchBtn" type="button" class="btn btn-default">查询</button>
            </div>
        </div>
    </div>
    <!-- 删除 -->
    <div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2"
        role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×</button>
                    <h4 class="modal-title">删除联赛</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-12">
                            删除后无法恢复,请谨慎操作! <br />确定要删除吗?
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取
                        消</button>
                    <button id="okDel" type="button" class="btn btn-primary"
                        data-loading-text="正在删除...">确 定</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 详情 -->
    <div id="dialogDetail" class="modal fade bs-modal-sm" tabindex="-3"
        role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content"></div>
        </div>
    </div>
    <script language="JavaScript" type="text/javascript">
        function exportData(obj) {
            window.location.href="${base}/platform/changxinyun/export?searchKey="+$('#searchKey').val();
        }

        function jsCopy(stem) {
            if (stem == 1) {
                var e = document.getElementById("pushUrl");//对象是content 
            } else {
                var e = document.getElementById("pushSecret");//对象是content 
            }
            e.select(); //选择对象 
            document.execCommand("Copy"); //执行浏览器复制命令
            alert("已复制好,可贴粘。");
        }

        var datatable;
        function initDatatable() {
            datatable = $('.datatable')
                    .DataTable(
                            {
                                "dom" : '<"toolbar">frtip',
                                "searching" : false,
                                "processing" : false,
                                "serverSide" : true,
                                "select" : true,
                                "ordering" : false,
                                "language" : {
                                    "url" : "${base}/assets/plugins/datatables/cn.json"
                                },
                                "preDrawCallback" : function() {
                                    sublime.showLoadingbar($(".main-content"));
                                },
                                "drawCallback" : function() {
                                    sublime.closeLoadingbar($(".main-content"));
                                },
                                "ajax" : {
                                    "url" : "${base}/platform/changxinyun/data?t="
                                            + Math.random()+"&startDealWithTimeMills=${startDealWithTimeMills!}",
                                    "type" : "post",
                                    "data" : function(d) {
                                        d.searchKey = $('#searchKey').val();
                                        //alert("oos");
                                    }
                                },
                                "order" : [ [ 0, "desc" ] ],
                                "columns" : [{
                                    "data" : null,
                                    "bSortable" : true
                                },{
                                    "data" : "name",
                                    "bSortable" : true
                                },{
                                    "data" : "pid",
                                    "bSortable" : true
                                },{
                                    "data" : "phone",
                                    "bSortable" : true
                                },{
                                    "data" : null,
                                    "bSortable" : true
                                },{
                                    "data" : "result",
                                    "bSortable" : true
                                }],
                                "columnDefs" : [{
                                            "render" : function(data, type, row) {
                                                return row.orderby;
                                            },
                                            "targets" : 0
                                        },{
                                            "render" : function(data, type, row) {
                                                return "实名认证";
                                            },
                                            "targets" :4 
                                        }]
                            });
            datatable.on('click', 'tr', function() {
                $(this).toggleClass('selected');
            });

            $("#searchBtn").on('click', function() {

                datatable.ajax.reload();
            });
            if (datatable) {
                datatable.ajax.reload();
                datatable.ajax.reload();
            }
        }

        function del(id) {
            var dialog = $("#dialogDelete");
            dialog.modal("show");
            dialog.find("#okDel").unbind("click");
            dialog.find("#okDel").bind("click", function(event) {
                var btn = $(this);
                btn.button("loading");
                $.post("${base}/bigroom/delete/" + id, {}, function(data) {
                    if (data.code == 0) {
                        $("#searchBtn").trigger("click");
                        Toast.success(data.msg);
                        datatable.ajax.reload(null, false);
                    } else {
                        Toast.error(data.msg);
                    }
                    //重置按钮状态,关闭提示框
                    btn.button("reset");
                    dialog.modal("hide");
                }, "json");
            });
        }

        function startLiving(id, pushliveurl, pushsecret) {
            var dialog = $("#dialogStart");
            $("#pushUrl").val(pushliveurl);
            $("#pushSecret").val(pushsecret);
            dialog.modal("show");
            dialog.find("#okStart").unbind("click");
            debugger;
            dialog.find("#okStart").bind("click", function(event) {
                var btn = $(this);
                $.ajax({
                    type : "post",
                    url : "${base}/bigroom/updateState",
                    data : "id=" + id + "&state=" + 1,
                    success : function(data) {
                        var obj = eval('(' + JSON.stringify(data) + ')');
                        if (data.code == 0) {
                            $("#searchBtn").trigger("click");
                            /* window.location.reload(); */
                            Toast.success(data.msg);
                        } else {
                            Toast.error(data.msg);
                        }
                    }
                });
                btn.button("loading");
                btn.button("reset");
                dialog.modal("hide");
            });
            dialog.find("#cope1").unbind("click");
            dialog.find("#cope1").bind("click", function(event) {
                var btn = $(this);
                var e = document.getElementById("pushUrl");//对象是content 
                e.select(); //选择对象 
                document.execCommand("Copy"); //执行浏览器复制命令
                alert("已复制好,可贴粘。");
            });
            dialog.find("#cope2").unbind("click");
            dialog.find("#cope2").bind("click", function(event) {
                var btn = $(this);
                var e = document.getElementById("pushSecret");//对象是content 
                e.select(); //选择对象 
                document.execCommand("Copy"); //执行浏览器复制命令
                alert("已复制好,可贴粘。");
            });
        }
        $(function() {
            initDatatable();
        });
    </script>
    <%}%>



- 效果图 -






学习参考地址

名称路径备注
nutz首页 http://nutzam.com/index.html nutz首页,Nutz 1.r.65(怪物猎人)发布
github地址https://github.com/nutzam开发配套的源码地址,可以再github搜索”nutz
apidochttp://www.nutzam.com/core/dao/basic_operations.html#nutz帮助文档地址
分布式https://www.oschina.net/news/94388/nutzwk-5-0-1-releasedNutzWk 5.0.1 发布,Java 微服务分布式开发框架
其他源码地址https://github.com/wendal/nutz-book-projectNutz 活跃开发作者:wendal,github地址








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值