上传下载加分页

来源:互联网 发布:微软雅黑bold for mac 编辑:程序博客网 时间:2024/06/06 13:02
上传下载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;        });    }});