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);
}

方式二:code

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文件上傳get

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);
}
相關文章
相關標籤/搜索