热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

android图片压缩工具类分享

这篇文章主要为大家分享了android图片压缩工具类,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了android图片压缩工具类的具体代码,供大家参考,具体内容如下

import java.io.BufferedOutputStream; 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.BitmapFactory.Options; 
import android.graphics.Matrix; 
import android.net.Uri; 
import android.widget.Toast; 
 
/** 
 * 圆形图片工具类 
 * 
 * @author SKLM 
 * 
 */ 
public class ImageViewTool { 
 
  /** 
   * 我们先看下质量压缩方法 
   * 
   * @param image 
   * @return 
   */ 
  public static Bitmap compressImage(Bitmap image) { 
 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    image.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 
    int optiOns= 100; 
    while (baos.toByteArray().length / 1024 > 100) { // 循环判断如果压缩后图片是否大于100kb,大于继续压缩 
      baos.reset();// 重置baos即清空baos 
      image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%,把压缩后的数据存放到baos中 
      options -= 10;// 每次都减少10 
    } 
    ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中 
    Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);// 把ByteArrayInputStream数据生成图片 
    return bitmap; 
  } 
 
  /** 
   * 图片按比例大小压缩方法(根据路径获取图片并压缩) 
   * 
   * @param srcPath 
   * @return 
   */ 
  public static Bitmap getimage(String srcPath) { 
    BitmapFactory.Options newOpts = new BitmapFactory.Options(); 
    // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 
    newOpts.inJustDecodeBounds = true; 
    Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts);// 此时返回bm为空 
 
    newOpts.inJustDecodeBounds = false; 
    int w = newOpts.outWidth; 
    int h = newOpts.outHeight; 
    // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为 
    float hh = 800f;// 这里设置高度为800f 
    float ww = 480f;// 这里设置宽度为480f 
    // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 
    int be = 1;// be=1表示不缩放 
    if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放 
      be = (int) (newOpts.outWidth / ww); 
    } else if (w  hh) {// 如果高度高的话根据宽度固定大小缩放 
      be = (int) (newOpts.outHeight / hh); 
    } 
    if (be <= 0) 
      be = 1; 
    newOpts.inSampleSize = be;// 设置缩放比例 
    // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 
    bitmap = BitmapFactory.decodeFile(srcPath, newOpts); 
    return compressImage(bitmap);// 压缩好比例大小后再进行质量压缩 
  } 
 
  /** 
   * 图片按比例大小压缩方法(根据Bitmap图片压缩) 
   * 
   * @param image 
   * @return 
   */ 
  public static Bitmap comp(Bitmap image) { 
 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    image.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
    if (baos.toByteArray().length / 1024 > 1024) {// 判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出 
      baos.reset();// 重置baos即清空baos 
      image.compress(Bitmap.CompressFormat.JPEG, 30, baos);// 这里压缩50%,把压缩后的数据存放到baos中 
    } 
    ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); 
    BitmapFactory.Options newOpts = new BitmapFactory.Options(); 
    // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 
    newOpts.inJustDecodeBounds = true; 
    Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, newOpts); 
    newOpts.inJustDecodeBounds = false; 
    int w = newOpts.outWidth; 
    int h = newOpts.outHeight; 
    // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为 
    float hh = 150f;// 这里设置高度为800f 
    float ww = 150f;// 这里设置宽度为480f 
    // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 
    int be = 1;// be=1表示不缩放 
    if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放 
      be = (int) (newOpts.outWidth / ww); 
    } else if (w  hh) {// 如果高度高的话根据宽度固定大小缩放 
      be = (int) (newOpts.outHeight / hh); 
    } 
    if (be <= 0) 
      be = 1; 
    newOpts.inSampleSize = be;// 设置缩放比例 
    // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 
    isBm = new ByteArrayInputStream(baos.toByteArray()); 
    bitmap = BitmapFactory.decodeStream(isBm, null, newOpts); 
    return compressImage(bitmap);// 压缩好比例大小后再进行质量压缩 
  } 
 
  public static byte[] Bitmap2Bytes(Bitmap bm) { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos); 
    return baos.toByteArray(); 
  } 
 
  /** 
   * 按原比例压缩图片到指定尺寸 
   * 
   * @param context 
   * @param inputUri 
   * @param outputUri 
   * @param maxLenth 
   *      最长边长 
   */ 
  public static void reducePicture(Context context, Uri inputUri, 
      Uri outputUri, int maxLenth, int compress) { 
    Options optiOns= new Options(); 
    options.inJustDecodeBounds = true; 
    InputStream is = null; 
    try { 
      is = context.getContentResolver().openInputStream(inputUri); 
      BitmapFactory.decodeStream(is, null, options); 
      is.close(); 
      int sampleSize = 1; 
      int lOngestSide= 0; 
      int lOngestSideLenth= 0; 
      if (options.outWidth > options.outHeight) { 
        lOngestSideLenth= options.outWidth; 
        lOngestSide= 0; 
      } else { 
        lOngestSideLenth= options.outHeight; 
        lOngestSide= 1; 
      } 
      if (longestSideLenth > maxLenth) { 
        sampleSize = longestSideLenth / maxLenth; 
      } 
      options.inJustDecodeBounds = false; 
      options.inSampleSize = sampleSize; 
 
      is = context.getContentResolver().openInputStream(inputUri); 
      Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); 
      is.close(); 
 
      if (bitmap == null) { 
        Toast.makeText(context, "图片获取失败,请确认您的存储卡是否正常", 
            Toast.LENGTH_SHORT).show(); 
        return; 
      } 
 
      Bitmap srcBitmap = bitmap; 
      float scale = 0; 
      if (lOngestSide== 0) { 
        scale = (float) maxLenth / (float) (srcBitmap.getWidth()); 
      } else { 
        scale = (float) maxLenth / (float) (srcBitmap.getHeight()); 
      } 
      Matrix matrix = new Matrix(); 
      matrix.postScale(scale, scale); 
      bitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), 
          srcBitmap.getHeight(), matrix, true); 
      // 如果尺寸不变会返回本身,所以需要判断是否是统一引用来确定是否需要回收 
      if (srcBitmap != bitmap) { 
        srcBitmap.recycle(); 
        srcBitmap = null; 
      } 
 
      saveBitmapToUri(bitmap, outputUri, compress); 
      bitmap.recycle(); 
      bitmap = null; 
    } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
    } 
  } 
 
  private static boolean saveBitmapToUri(Bitmap bitmap, Uri uri, int compress) 
      throws IOException { 
    File file = new File(uri.getPath()); 
    if (file.exists()) { 
      if (file.delete()) { 
        if (!file.createNewFile()) { 
          return false; 
        } 
      } 
    } 
 
    BufferedOutputStream outStream = new BufferedOutputStream( 
        new FileOutputStream(file)); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, compress, outStream); 
    outStream.flush(); 
    outStream.close(); 
 
    return true; 
  } 
 
} 

接下来看看第二个写法压缩图片的工具类,如下

import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.sql.Date; 
import java.text.SimpleDateFormat; 
 
import android.graphics.Bitmap; 
import android.graphics.Bitmap.Config; 
import android.graphics.BitmapFactory; 
import android.os.Environment; 
 
/** 
 * 图像压缩工厂类 
 * 
 * @author 
 * 
 */ 
public class ImageFactory { 
 
  /** 
   * 从指定的图像路径获取位图 
   * 
   * @param imgPath 
   * @return 
   */ 
  public Bitmap getBitmap(String imgPath) { 
    // Get bitmap through image path 
    BitmapFactory.Options newOpts = new BitmapFactory.Options(); 
    newOpts.inJustDecodeBounds = false; 
    newOpts.inPurgeable = true; 
    newOpts.inInputShareable = true; 
    // Do not compress 
    newOpts.inSampleSize = 1; 
    newOpts.inPreferredCOnfig= Config.RGB_565; 
    return BitmapFactory.decodeFile(imgPath, newOpts); 
  } 
 
  /** 
   * 压缩图片(质量压缩) 
   * 
   * @param bitmap 
   */ 
  public static File compressImage(Bitmap bitmap) { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 
    int optiOns= 100; 
    while (baos.toByteArray().length / 1024 > 500) { // 循环判断如果压缩后图片是否大于500kb,大于继续压缩 
      baos.reset();// 重置baos即清空baos 
      options -= 10;// 每次都减少10 
      bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%,把压缩后的数据存放到baos中 
      long length = baos.toByteArray().length; 
    } 
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); 
    Date date = new Date(System.currentTimeMillis()); 
    String filename = format.format(date); 
    File file = new File(Environment.getExternalStorageDirectory(), filename + ".png"); 
    try { 
      FileOutputStream fos = new FileOutputStream(file); 
      try { 
        fos.write(baos.toByteArray()); 
        fos.flush(); 
        fos.close(); 
      } catch (IOException e) { 
 
        e.printStackTrace(); 
      } 
    } catch (FileNotFoundException e) { 
 
      e.printStackTrace(); 
    } 
    recycleBitmap(bitmap); 
    return file; 
  } 
 
  public static void recycleBitmap(Bitmap... bitmaps) { 
    if (bitmaps == null) { 
      return; 
    } 
    for (Bitmap bm : bitmaps) { 
      if (null != bm && !bm.isRecycled()) { 
        bm.recycle(); 
      } 
    } 
  } 
 
  /** 
   * 将位图存储到指定的图像路径中 
   * 
   * @param bitmap 
   * @param outPath 
   * @throws FileNotFoundException 
   */ 
  public void storeImage(Bitmap bitmap, String outPath) throws FileNotFoundException { 
    FileOutputStream os = new FileOutputStream(outPath); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os); 
  } 
 
  /** 
   * 通过像素压缩图像,这将改变图像的宽度/高度。用于获取缩略图 
   * 
   * 
   * @param imgPath 
   *      image path 
   * @param pixelW 
   *      目标宽度像素 
   * @param pixelH 
   *      高度目标像素 
   * @return 
   */ 
  public Bitmap ratio(String imgPath, float pixelW, float pixelH) { 
    BitmapFactory.Options newOpts = new BitmapFactory.Options(); 
    // 开始读入图片,此时把options.inJustDecodeBounds 设回true,即只读边不读内容 
    newOpts.inJustDecodeBounds = true; 
    newOpts.inPreferredCOnfig= Config.RGB_565; 
    // Get bitmap info, but notice that bitmap is null now 
    Bitmap bitmap = BitmapFactory.decodeFile(imgPath, newOpts); 
 
    newOpts.inJustDecodeBounds = false; 
    int w = newOpts.outWidth; 
    int h = newOpts.outHeight; 
    // 想要缩放的目标尺寸 
    float hh = pixelH;// 设置高度为240f时,可以明显看到图片缩小了 
    float ww = pixelW;// 设置宽度为120f,可以明显看到图片缩小了 
    // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 
    int be = 1;// be=1表示不缩放 
    if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放 
      be = (int) (newOpts.outWidth / ww); 
    } else if (w  hh) {// 如果高度高的话根据宽度固定大小缩放 
      be = (int) (newOpts.outHeight / hh); 
    } 
    if (be <= 0) 
      be = 1; 
    newOpts.inSampleSize = be;// 设置缩放比例 
    // 开始压缩图片,注意此时已经把options.inJustDecodeBounds 设回false了 
    bitmap = BitmapFactory.decodeFile(imgPath, newOpts); 
    // 压缩好比例大小后再进行质量压缩 
    // return compress(bitmap, maxSize); // 这里再进行质量压缩的意义不大,反而耗资源,删除 
    return bitmap; 
  } 
 
  /** 
   * 压缩图像的大小,这将修改图像宽度/高度。用于获取缩略图 
   * 
   * 
   * @param image 
   * @param pixelW 
   *      target pixel of width 
   * @param pixelH 
   *      target pixel of height 
   * @return 
   */ 
  public Bitmap ratio(Bitmap image, float pixelW, float pixelH) { 
    ByteArrayOutputStream os = new ByteArrayOutputStream(); 
    image.compress(Bitmap.CompressFormat.JPEG, 100, os); 
    if (os.toByteArray().length / 1024 > 1024) {// 判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出 
      os.reset();// 重置baos即清空baos 
      image.compress(Bitmap.CompressFormat.JPEG, 50, os);// 这里压缩50%,把压缩后的数据存放到baos中 
    } 
    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); 
    BitmapFactory.Options newOpts = new BitmapFactory.Options(); 
    // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 
    newOpts.inJustDecodeBounds = true; 
    newOpts.inPreferredCOnfig= Config.RGB_565; 
    Bitmap bitmap = BitmapFactory.decodeStream(is, null, newOpts); 
    newOpts.inJustDecodeBounds = false; 
    int w = newOpts.outWidth; 
    int h = newOpts.outHeight; 
    float hh = pixelH;// 设置高度为240f时,可以明显看到图片缩小了 
    float ww = pixelW;// 设置宽度为120f,可以明显看到图片缩小了 
    // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 
    int be = 1;// be=1表示不缩放 
    if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放 
      be = (int) (newOpts.outWidth / ww); 
    } else if (w  hh) {// 如果高度高的话根据宽度固定大小缩放 
      be = (int) (newOpts.outHeight / hh); 
    } 
    if (be <= 0) 
      be = 1; 
    newOpts.inSampleSize = be;// 设置缩放比例 
    // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 
    is = new ByteArrayInputStream(os.toByteArray()); 
    bitmap = BitmapFactory.decodeStream(is, null, newOpts); 
    // 压缩好比例大小后再进行质量压缩 
    // return compress(bitmap, maxSize); // 这里再进行质量压缩的意义不大,反而耗资源,删除 
    return bitmap; 
  } 
 
  /** 
   * 按质量压缩,并将图像生成指定的路径 
   * 
   * @param image 
   * @param outPath 
   * @param maxSize 
   *      目标将被压缩到小于这个大小(KB)。 
   * @throws IOException 
   */ 
  public void compressAndGenImage(Bitmap image, String outPath, int maxSize) throws IOException { 
    ByteArrayOutputStream os = new ByteArrayOutputStream(); 
    // scale 
    int optiOns= 100; 
    // Store the bitmap into output stream(no compress) 
    image.compress(Bitmap.CompressFormat.JPEG, options, os); 
    // Compress by loop 
    while (os.toByteArray().length / 1024 > maxSize) { 
      // Clean up os 
      os.reset(); 
      // interval 10 
      options -= 10; 
      image.compress(Bitmap.CompressFormat.JPEG, options, os); 
    } 
 
    // Generate compressed image file 
    FileOutputStream fos = new FileOutputStream(outPath); 
    fos.write(os.toByteArray()); 
    fos.flush(); 
    fos.close(); 
  } 
 
  /** 
   * 按质量压缩,并将图像生成指定的路径 
   * 
   * @param imgPath 
   * @param outPath 
   * @param maxSize 
   *      目标将被压缩到小于这个大小(KB)。 
   * @param needsDelete 
   *      是否压缩后删除原始文件 
   * @throws IOException 
   */ 
  public void compressAndGenImage(String imgPath, String outPath, int maxSize, boolean needsDelete) 
      throws IOException { 
    compressAndGenImage(getBitmap(imgPath), outPath, maxSize); 
 
    // Delete original file 
    if (needsDelete) { 
      File file = new File(imgPath); 
      if (file.exists()) { 
        file.delete(); 
      } 
    } 
  } 
 
  /** 
   * 比例和生成拇指的路径指定 
   * 
   * @param image 
   * @param outPath 
   * @param pixelW 
   *      目标宽度像素 
   * @param pixelH 
   *      高度目标像素 
   * @throws FileNotFoundException 
   */ 
  public void ratioAndGenThumb(Bitmap image, String outPath, float pixelW, float pixelH) 
      throws FileNotFoundException { 
    Bitmap bitmap = ratio(image, pixelW, pixelH); 
    storeImage(bitmap, outPath); 
  } 
 
  /** 
   * 比例和生成拇指的路径指定 
   * 
   * @param image 
   * @param outPath 
   * @param pixelW 
   *      目标宽度像素 
   * @param pixelH 
   *      高度目标像素 
   * @param needsDelete 
   *      是否压缩后删除原始文件 
   * @throws FileNotFoundException 
   */ 
  public void ratioAndGenThumb(String imgPath, String outPath, float pixelW, float pixelH, boolean needsDelete) 
      throws FileNotFoundException { 
    Bitmap bitmap = ratio(imgPath, pixelW, pixelH); 
    storeImage(bitmap, outPath); 
 
    // Delete original file 
    if (needsDelete) { 
      File file = new File(imgPath); 
      if (file.exists()) { 
        file.delete(); 
      } 
    } 
  } 
 
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了如何使用Power Design(PD)和SQL Server进行数据库反向工程的方法。通过创建数据源、选择要反向工程的数据表,PD可以生成物理模型,进而生成所需的概念模型。该方法适用于SQL Server数据库,对于其他数据库是否适用尚不确定。详细步骤和操作说明可参考本文内容。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • 本文介绍了adg架构设置在企业数据治理中的应用。随着信息技术的发展,企业IT系统的快速发展使得数据成为企业业务增长的新动力,但同时也带来了数据冗余、数据难发现、效率低下、资源消耗等问题。本文讨论了企业面临的几类尖锐问题,并提出了解决方案,包括确保库表结构与系统测试版本一致、避免数据冗余、快速定位问题等。此外,本文还探讨了adg架构在大版本升级、上云服务和微服务治理方面的应用。通过本文的介绍,读者可以了解到adg架构设置的重要性及其在企业数据治理中的应用。 ... [详细]
  • 本文介绍了使用postman进行接口测试的方法,以测试用户管理模块为例。首先需要下载并安装postman,然后创建基本的请求并填写用户名密码进行登录测试。接下来可以进行用户查询和新增的测试。在新增时,可以进行异常测试,包括用户名超长和输入特殊字符的情况。通过测试发现后台没有对参数长度和特殊字符进行检查和过滤。 ... [详细]
  • 本文详细介绍了MysqlDump和mysqldump进行全库备份的相关知识,包括备份命令的使用方法、my.cnf配置文件的设置、binlog日志的位置指定、增量恢复的方式以及适用于innodb引擎和myisam引擎的备份方法。对于需要进行数据库备份的用户来说,本文提供了一些有价值的参考内容。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
author-avatar
w3cbj.cn
w3c笔记,程序员专属笔记云平台,24种代码高亮!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有