JFinal常用功能,非常方便

一 :JFinal获取前端传过来的参数

方式一:

    public void submit() {
    RespBody respbody = new RespBody();
    Contact contact = getModel(Contact.class ,"contact");
    String contactName = contact.getStr("contactName");
    logger.info("--------这样就可以获取参数啦----------"+contactName);
    contact.save();
    respbody.setResult(true);
    respbody.setData(contact);
    renderJson(respbody);
}

方式二:

    public void delete() {
    RespBody respbody = new RespBody();
    int id = getParaToInt("id");
    logger.info("--------这样就可以获取参数啦----------"+id);
    if (Contact.dao.deleteById(id)) {
        respbody.setResult(true);
    }else {
        respbody.setMsg("刪除失败,请检查是否存在该id   ");
    }
    renderJson(respbody);
}

二:JFinal文件上传

    public void upload(  ){
    RespBody resp = new RespBody();
    try {
        UploadFile file = getFile();
        System.out.println("--------file--------");
        File delfile = new File(file.getUploadPath()+"\\"+file.getFileName());
        System.out.println("=========="+delfile.getPath());
        resp.setResult(true);
        Map<String ,String> map = new HashMap<String, String>();
        map.put("filePath", delfile.getPath());
        map.put("fileSize", delfile.length()/1024+"");
        resp.setData(map);
    } catch (Exception e) {
        e.printStackTrace();
        resp.setMsg("文件上传失败");
    }
    
    renderJson(resp);
}

三:JFinal数据库分页查询

   public void getPage() {
    RespBody respbody = new RespBody();
    try {
        int pageSize = getParaToInt("pageSize");
        int pageNumber = getParaToInt("pageNumber");
        int type = getParaToInt("type");
        Page<Record> download = Db.paginate(pageNumber, pageSize, "select * ", "from download where                      

        file_type="+type);
        respbody.setData(download);
        respbody.setResult(true);
    } catch (Exception e) {
        e.printStackTrace();
        respbody.setMsg("请检查参数是否遗漏");
    }
    renderJson(respbody);
}

猜你喜欢

转载自my.oschina.net/u/3303751/blog/967917
今日推荐