java-查询图片url导出到本地

SQL查询语句附给一个变量list,遍历,取每个图片的url,定义本地路径,fastdfsService的copyFileFromDfs方法将图片下载到本地。

public void import1() {
        /**
         * SELECT
         * imc.id,imc.img_md5,imc.img_url,imc.thumb_width,imc.thumb_height
         * ,imc.img_url_thumb,c.serial_number from img_center imc left join
         * img_case c on imc.case_id=c.id where
         * source_id='8310f5b97fe54a6495688263fa6ca928' and c.create_user =
         * '2-2-1'
         * 
         * SELECT
         * imc.id,imc.img_md5,imc.img_url,imc.thumb_width,imc.thumb_height
         * ,imc.img_url_thumb from img_center imc left join img_case c on
         * imc.case_id=c.id where source_id='8310f5b97fe54a6495688263fa6ca928'
         * and c.create_user='正常'
         * 
         * SELECT
         * imc.id,imc.img_md5,imc.img1024_url,imc.thumb_width,imc.thumb_height
         * ,imc.img_url_thumb,c.img_info from img_center imc left join img_case
         * c on imc.case_id=c.id where
         * c.source_id='8310f5b97fe54a6495688263fa6ca928' and imc.img_md5
         * in(SELECT img_md5 FROM tag_img WHERE
         * type_id='740bc5fb849f451fad666dae1dcbb0f0' AND tag_json IS NOT NULL)
         */

        //TagImgFilter filter = new TagImgFilter();
        //filter.setEq_typeId("413f225ed6a745c2b88cfb5d6053fc1d");
        //filter.setNull_tagJson(false);

        //List<Map<String, Object>> list = jdbcTemplate
        //        .queryForList("SELECT t.img_md5,imc.img1024_url FROM tag_img t LEFT JOIN img_center imc ON t.img_md5=imc.img_md5 WHERE t.type_id='5d8f5f9aecb14e54aef64f55aec57b5b' and t.del_flag=1 and t.tag_flag=1 and imc.del_flag=1");
        /*List<Map<String, Object>> list = jdbcTemplate
                .queryForList("SELECT t.id,imc.img1024_url FROM tag_img t LEFT JOIN img_center imc ON t.img_md5=imc.img_md5 WHERE type_id='5976d4dda1e141c181d3e7bdaba7ae9f' AND t.del_flag=1 AND t.img_md5 NOT IN (SELECT img_md5 FROM tag_img WHERE set_id='6f2b4c77fdab4137aeabda9282c0c597' AND del_flag=1)");
*/
        List<Map<String, Object>> list = jdbcTemplate
                .queryForList("SELECT id,img_url FROM tag_img WHERE type_id='672497aee4a84a49b78a60b78602166e' and del_flag=1 and tag_flag=1");

        int i = 0;

        for (Map<String, Object> tagimg : list) {
            //String img1024Url = tagimg.get("img1024_url").toString();//获取img1024_url
            String imgUrl = tagimg.get("img_url").toString();
            //String imgMD5 = tagimg.get("img_md5").toString();
            String id = tagimg.get("id").toString();
            i++;
            System.out.println(i);
            //System.out.println(i+ "_" +imgMD5);

            System.out.println(imgUrl);
            String path = "D:/downloadjpg/yang";
            //String localPath = path + "/" + imgMD5 + ".jpg";
            //String localPath = path + "/" + i + "_" +imgMD5 + ".jpg";
            String localPath = path + "/" + id +".jpg";
            
            //fastdfsService.copyFileFromDfs(img1024Url, localPath);
            fastdfsService.copyFileFromDfs(imgUrl, localPath);
        }

 

posted @ 2019-01-09 09:45  yangly  阅读(733)  评论(0编辑  收藏  举报