JFinal常用功能,非常方便

本文介绍了JFinal框架下三种常见操作的实现方法:从前端获取参数、文件上传及数据库分页查询。通过具体代码示例展示了如何使用JFinal进行高效开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

转载于:https://my.oschina.net/u/3303751/blog/967917

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值