• 知识点


    不分页获取图片

    controller

     1     /**
     2      * 获取特卫服务类型(所有)
     3      * @param request
     4      * @param response
     5      * @param time_stamp
     6      * @param sig
     7      * @param callback
     8      */
     9     @RequestMapping("/queryAllTType")
    10     public void queryAllTType(HttpServletRequest request,HttpServletResponse response,
    11             @RequestParam("time_stamp") String time_stamp,@RequestParam("sig") String sig,@RequestParam("callback") String callback){
    12         String localhost = FileUtil.getLocalhost();
    13         Map<String,Object> map=new HashMap<String,Object>();
    14         map=ParameterValidation.validateParameter(time_stamp, sig, "queryAllTType");
    15         if(map.get("code")==null){
    16             List<SgTaskType> list=sgTaskTypeServiceImpl.findAllType();
    17             List<SgTaskType> lastlist = new ArrayList<SgTaskType>();
    18              if(list!=null&&list.size()>0){
    19                     for(SgTaskType pic : list){
    20                          pic.setPicture(localhost+request.getContextPath()+"/pc/sg/findSgTaskTypeCoverImg?id="+pic.getId()+".png");
    21                          lastlist.add(pic);
    22                     }
    23                 }
    24             map.put("data", list);
    25             map.put("code", 200);
    26         }
    27         returnEntityToJson(response, callback, map);
    28     }
    29 
    30 /**
    31      * 获取特卫任务图片
    32      * @param request
    33      * @param response
    34      * @param id
    35      */
    36     @RequestMapping("/findSgTaskTypeCoverImg")
    37     public void findSgTaskTypeCoverImg(HttpServletRequest request,HttpServletResponse response,@RequestParam("id") String id){
    38         Map<String,Object> map = new HashMap<String,Object>();
    39         if(id==null||"".equals(id)){    
    40             map.put("code", 201);//id号为空
    41             map.put("data", null);
    42             returnEntityToJson(response,map);
    43             return;
    44         }
    45         String attr[] = id.split(".png");
    46         SgTaskType Ttype = sgTaskTypeServiceImpl.findEntityById(attr[0]);
    47         if(Ttype!=null){
    48             String imgpath = Ttype.getPicture();
    49             if(imgpath!=null&&!"".equals(imgpath)){
    50                 byte[] s = FileUtil.loadFile(imgpath);
    51                 if(s!=null&&s.length>0){
    52                     response.reset();
    53                     try {
    54                         response.getOutputStream().write(s);
    55                     } catch (IOException e) {
    56                         // TODO Auto-generated catch block
    57                         e.printStackTrace();
    58                     }
    59                 }else{
    60                     byte[] s1 = FileUtil.loadFile(FileUtil.getPro("/filePath.properties","defaultCover"));
    61                     if(s1!=null&&s1.length>0){
    62                         response.reset();
    63                         try {
    64                             response.getOutputStream().write(s1);
    65                         } catch (IOException e) {
    66                             // TODO Auto-generated catch block
    67                             e.printStackTrace();
    68                         }
    69                     }
    70                 }
    71             }
    72         }
    73     }

    service

    1 public List<SgTaskType> findAllType(){
    2         
    3         return sgTaskTypeDao.findALLType();
    4         
    5     }

    dao

    @Query("select t from SgTaskType t where 1=1")
        List<SgTaskType> findALLType();
    //通过id查 @Query(
    "from SgTaskType t where t.id=:id") List<SgTaskType> findAllTaskTypeById(@Param("id") String id);

    分页获取图片(获取图片与不分页同,用同一个即可)

    controller

     1     /**
     2      * 获取特卫服务的类型(贴身保镖,逛街拎包,接送孩子等)----分页
     3      * @param request
     4      * @param response
     5      * @param time_stamp
     6      * @param sig
     7      */
     8     @RequestMapping("/queryALLSgTaskType")
     9     public void queryALLSgTaskType(HttpServletRequest request,HttpServletResponse response,
    10             @RequestParam("time_stamp") String time_stamp,@RequestParam("sig") String sig,@RequestParam("callback") String callback,
    11             @RequestParam("page") int page,@RequestParam("rows") int rows){
    12         String localhost = FileUtil.getLocalhost();
    13         Map<String,Object> map=new HashMap<String,Object>();
    14         map=ParameterValidation.validateParameter(time_stamp, sig, "queryALLSgTaskType");
    15         if(map.get("code")==null){
    16             List<SgTaskType> list=sgTaskTypeServiceImpl.findSgTaskTypeForPage((page-1)*rows, rows);
    17             List<SgTaskType> lastlist = new ArrayList<SgTaskType>();
    18              if(list!=null&&list.size()>0){
    19                     for(SgTaskType pic : list){
    20                          pic.setPicture(localhost+request.getContextPath()+"/pc/sg/findSgTaskTypeCoverImg?id="+pic.getId()+".png");
    21                          lastlist.add(pic);
    22                     }
    23                 }
    24             map.put("data", list);
    25             map.put("code",200);
    26         }
    27         returnEntityToJson(response, callback, map);
    28     }
    29     /**
    30      * 获取特卫任务图片
    31      * @param request
    32      * @param response
    33      * @param id
    34      */
    35     @RequestMapping("/findSgTaskTypeCoverImg")
    36     public void findSgTaskTypeCoverImg(HttpServletRequest request,HttpServletResponse response,@RequestParam("id") String id){
    37         Map<String,Object> map = new HashMap<String,Object>();
    38         if(id==null||"".equals(id)){    
    39             map.put("code", 201);//id号为空
    40             map.put("data", null);
    41             returnEntityToJson(response,map);
    42             return;
    43         }
    44         String attr[] = id.split(".png");
    45         SgTaskType Ttype = sgTaskTypeServiceImpl.findEntityById(attr[0]);
    46         if(Ttype!=null){
    47             String imgpath = Ttype.getPicture();
    48             if(imgpath!=null&&!"".equals(imgpath)){
    49                 byte[] s = FileUtil.loadFile(imgpath);
    50                 if(s!=null&&s.length>0){
    51                     response.reset();
    52                     try {
    53                         response.getOutputStream().write(s);
    54                     } catch (IOException e) {
    55                         // TODO Auto-generated catch block
    56                         e.printStackTrace();
    57                     }
    58                 }else{
    59                     byte[] s1 = FileUtil.loadFile(FileUtil.getPro("/filePath.properties","defaultCover"));
    60                     if(s1!=null&&s1.length>0){
    61                         response.reset();
    62                         try {
    63                             response.getOutputStream().write(s1);
    64                         } catch (IOException e) {
    65                             // TODO Auto-generated catch block
    66                             e.printStackTrace();
    67                         }
    68                     }
    69                 }
    70             }
    71         }
    72     }

    seivice

     1 /**
     2      * pc查询任务类型(分页)
     3      * @param page
     4      * @param rows
     5      * @return
     6      */
     7     public List<SgTaskType> findSgTaskTypeForPage(int page,int rows){
     8         return spTaskTypeDaoImpl.findTaskTypeForPage(page, rows);
     9     }
    10     

    dao.impl

    @Component
    public class SgTaskTypeDaoImpl {
    
        @PersistenceContext
        EntityManager entityManager;
        
        public List<SgTaskType> findTaskTypeForPage(int page,int rows){
            
            String sql="select * from t_sgtasktype";
            List<SgTaskType> sg=new ArrayList<SgTaskType>();
            sg=entityManager.createNativeQuery(sql,SgTaskType.class).setFirstResult(page).setMaxResults(rows).getResultList();
            if(!sg.isEmpty()){
                return sg;
            }else{
                return null;
            }
            
        }
    }
  • 相关阅读:
    tcpprep 对IPV6的支持
    the server quit without updating pid file (/var/lib/mysql/localhost.localdomain.pid)
    servlet service() for servlet jsp throws null pointer exception
    tomcat开机启动
    mysql 允许远程访问
    spring的helloworld
    java中的那些坑
    关于struts2中的相对路径与绝对路径
    Powercenter Source Filter
    oracle删除当前用户的表
  • 原文地址:https://www.cnblogs.com/yunqing/p/6647258.html
Copyright © 2020-2023  润新知