上传下载加分页

上传下载
public String update(House house, MultipartFile multipartFile, HttpServletRequest request) throws IOException {
    String filename = multipartFile.getOriginalFilename();
    //获取新的文件名
    long millis = System.currentTimeMillis();
    String newName = millis+filename;
    //获取文件流
    InputStream inputStream1 = multipartFile.getInputStream();
    //获取物理路径D:\ideal work\aa\web
    String wlPath = "D:\\ideal work\\fourDemo\\web\\images\\"+newName;
    String ljPath = "../images/"+newName;
    String pathRoot = request.getSession().getServletContext().getRealPath("/");//自动寻找target根目录
    String lsPath = pathRoot+"\\images\\"+newName;
    File wlFile = new File("D:\\ideal work\\fourDemo\\web\\images");
    File lsFile = new File(pathRoot+"\\images\\");
    if(!wlFile.exists()) {
        wlFile.mkdir();
    }
    if(!lsFile.exists()) {
        lsFile.mkdir();
    }
    if(!multipartFile.isEmpty()) {
        //将文件放入物理路径
        FileOutputStream wlFileOutputStream = new FileOutputStream(wlPath);
        //将文件放入临时路径
        FileOutputStream lsFileOutputStream1 =new FileOutputStream(lsPath);
        int line = 0;
        while ((line = inputStream1.read()) != -1) {
            //写入物理路径
            wlFileOutputStream.write(line);
            //写入临时路径
            lsFileOutputStream1.write(line);
        }

        wlFileOutputStream.flush();
        lsFileOutputStream1.flush();
        lsFileOutputStream1.close();
        wlFileOutputStream.close();
        inputStream1.close();
    }
    house.setHimg(ljPath);
    service.update(house);
    return "redirect:/house/show";
}
分页
public String show(HttpServletRequest request,Integer id,String pageNo, String pageSize){
    int num = 1;
    int size = 3;
    if(pageNo != null && !"".equals(pageNo)) {
        num = Integer.parseInt(pageNo);
    }
    if (pageSize != null && !"".equals(pageSize)) {
        size = Integer.parseInt(pageSize);
    }
    PageHelper.startPage(num,size);
    //查询数据库信息
    List<House> all = service.findAll(id);
    //将信息放入PageInfo进行分页
    PageInfo<House> pageInfo = new PageInfo<House>(all);
    request.setAttribute("pageHelper",pageInfo);
    return "show";
}
Jsp_______________________________
<span>${pageHelper.total}条记录当前显示</span><span>现在显示第${pageHelper.pageNum}</span>

<a href="/house/show?pageNo=${pageHelper.firstPage}&pageSize=${pageHelper.pageSize}" >首页</a>

        <c:if test="${pageHelper.isFirstPage == true}">
            <a href="/house/show?pageNo=${pageHelper.firstPage}&pageSize=${pageHelper.pageSize}" >上一页</a>
        </c:if>
        <c:if test="${pageHelper.isFirstPage != true}">
            <a href="/house/show?pageNo=${pageHelper.prePage}&pageSize=${pageHelper.pageSize}">上一页</a>
        </c:if>
<c:if test="${pageHelper.isLastPage == true}">
    <a href="/house/show?pageNo=${pageHelper.lastPage}&pageSize=${pageHelper.pageSize}">下一页</a>
</c:if>
<c:if test="${pageHelper.isLastPage != true}">
    <a href="/house/show?pageNo=${pageHelper.nextPage}&pageSize=${pageHelper.pageSize}">下一页</a>
</c:if>
<a href="/house/show?pageNo=${pageHelper.lastPage}&pageSize=${pageHelper.pageSize}">尾页</a>
$("#btn").click(function () {
    var arr=$(":checked");
    var ids=[];
    $.each(arr, function() {
        if(this.value>0){
            if(this.checked){
                ids.push($(this).val());
            }
        }
    });
    if(ids.length==0){
        alert("最少选中一个");
    }
     //location.href="/house/del?ids="+ids.join(",");
});
$("#dian").click(function(){
    var arr=$("[type=checkbox]");

    if(this.checked){
        $.each(arr, function() {
            this.checked=true;
        });
    }else{
        $.each(arr, function() {
            this.checked=false;
        });
    }
});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值