搜索词>>NULL 耗时0.0070
  • MySQL null转0

    MySQL查询中null转0本文主要讲解MySQL数据库查询中,通过ifnull函数将null替换为0,同样也可以替换为其他值。MySQL查询中null转0 SQL:select  ifnull(fieldName,0)  from table_name
  • Gson 序列化NULL值

    前言在Gson中实现的默认行为是忽略空对象字段前言在Gson中实现的默认行为是忽略空对象字段。例如,如果在Employee对象中,我们不指定电子邮件(即电子邮件是null),那么电子邮件将不是序列化JSON输出的一部分。Gson忽略空字段,因为此行为允许更紧凑的JSON输出格式。​1.如何在序列化期间允许空值 要配置GSON实例来输出null,我们必须使用serializeNulls()的GsonBuilder对象。Gson gson = new GsonBuilder() .serializeNulls() .create();2.演示 让我们看一下Gson的行为,同时启用或禁用空字段序列化。这是员工类,有四个字段。我们将电子邮件字段设置为'null'。$title(Employee.java) public class Employee { private Integer id; private String firstName; private String lastName; private String email; }2.1。不要序列化空字段 JSON输出中没有空值的默认Gson序列化。$title(Main.java) Employee employeeObj = new Employee(1, "Lokesh", "Gupta", null); Gson gson = new GsonBuilder() .setPrettyPrinting() .create(); System.out.println(gson.toJson(employeeObj)); 运行输出结果为:{ "id": 1, "firstName": "Lokesh", "lastName": "Gupta" }2.2。序列化空字段 自定义Gson序列化,JSON输出中包含空值。$title(Main.java) Employee employeeObj = new Employee(1, "Lokesh", "Gupta", null); Gson gson = new GsonBuilder() .setPrettyPrinting() .serializeNulls() .create(); System.out.println(gson.toJson(employeeObj)); 执行输出结果:{ "id": 1, "firstName": "Lokesh", "lastName": "Gupta", "emailId": null } 显然,null字段在JSON输出中被序列化。
  • Could not load TestContextBootstrapper [null].

    spring boot项目运行单元测试失败,报错Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.错误日志:java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available. at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:145) at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:124) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:151) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:142) at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33) at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)V at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:157) at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:128) ... 19 more代码段 小部件
  • mybatis if else

    首先在mybatis语法中是没有 if else写法得,​不过有他的替代  choose,写法如下: <choose>l; <when test="params!=null">l;首先在mybatis语法中是没有 if else写法得,​不过有他的替代  choose,写法如下: <choose> <when test="params!=null"> right JOIN </when> <otherwise> LEFT JOIN </otherwise> </choose>以上即可实现 if else 逻辑
  • Spring boot FastJson 返回JSON数据删除了NULL空字段解决办法

    在国内项目中,阿里的fastjson包因其使用简单功能强大很多人喜欢在项目中使用,我也是其中一员在国内项目中,阿里的fastjson包因其使用简单功能强大很多人喜欢在项目中使用,我也是其中一员。今天主要讨论的是在某些情况下因fastjson的默认配置删除了空的字段,这对于小项目的前端处理就有些恼火了,每次要验证所有的字段非空,为了简单还是将null值转换为空串比较方便。下面就spring boot项目中存在该问题进行解决。首先在web配置中找到fastjson的响应配置,如下: @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullNumberAsZero); fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }上面的配置中以下代码片段为配置fastjson不删除null的String字段,并将null字段返回空串: fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullNumberAsZero);
  • mybaties mapper 继承机制解决改表改mapper的苦恼

           本文主要讲解在使用mybaties中通过mybaties generator生成基本操作代码,然后通过 mybaties mapper 继承机制来解决某些情况下经常改表导致改mapper文件的苦恼       本文主要讲解在使用mybaties中通过mybaties generator生成基本操作代码,然后通过 mybaties mapper 继承机制来解决某些情况下经常改表导致改mapper文件的苦恼。好了废话少说上代码了首先是 mapper java文件的继承$title(ArticleMapper.java) public interface ArticleMapper { int deleteByPrimaryKey(Integer id); int insert(Article record); int insertSelective(Article record); Article selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Article record); int updateByPrimaryKey(Article record); }以上mapper文件为mybaties generator生成的代码。$title(ArticleExtMapper.java) public interface ArticleExtMapper extends ArticleMapper { Article getLast(@Param("id") Integer id, @Param("type") Integer type); Article getNext(@Param("id") Integer id, @Param("type") Integer type); List<Article> getList(@Param("title") String title, @Param("category") String category, @Param("type") Integer type); } 以上为业务使用中扩展的一些应用查询方法下面上mapper xml文件的使用$title(ArticleMapper.xml) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="net.ifok.ocms.business.mapper.ArticleMapper"> <resultMap id="BaseResultMap" type="net.ifok.ocms.business.model.Article"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="title" jdbcType="VARCHAR" property="title" /> <result column="image" jdbcType="VARCHAR" property="image" /> <result column="url" jdbcType="VARCHAR" property="url" /> <result column="content" jdbcType="VARCHAR" property="content" /> <result column="content_text" jdbcType="VARCHAR" property="contentText" /> <result column="category" jdbcType="VARCHAR" property="category" /> <result column="type" jdbcType="INTEGER" property="type" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="keywords" jdbcType="VARCHAR" property="keywords" /> <result column="description" jdbcType="VARCHAR" property="description" /> <result column="customer" jdbcType="VARCHAR" property="customer" /> </resultMap> <sql id="Base_Column_List"> id, title, image, url, content, content_text, category, type, create_time, update_time, keywords, description, customer </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from article where id = #{id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> delete from article where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="net.ifok.ocms.business.model.Article"> insert into article (id, title, image, url, content, content_text, category, type, create_time, update_time, keywords, description, customer) values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{contentText,jdbcType=VARCHAR}, #{category,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{keywords,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{customer,jdbcType=VARCHAR}) </insert> <insert id="insertSelective" parameterType="net.ifok.ocms.business.model.Article"> insert into article <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="title != null"> title, </if> <if test="image != null"> image, </if> <if test="url != null"> url, </if> <if test="content != null"> content, </if> <if test="contentText != null"> content_text, </if> <if test="category != null"> category, </if> <if test="type != null"> type, </if> <if test="createTime != null"> create_time, </if> <if test="updateTime != null"> update_time, </if> <if test="keywords != null"> keywords, </if> <if test="description != null"> description, </if> <if test="customer != null"> customer, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=INTEGER}, </if> <if test="title != null"> #{title,jdbcType=VARCHAR}, </if> <if test="image != null"> #{image,jdbcType=VARCHAR}, </if> <if test="url != null"> #{url,jdbcType=VARCHAR}, </if> <if test="content != null"> #{content,jdbcType=VARCHAR}, </if> <if test="contentText != null"> #{contentText,jdbcType=VARCHAR}, </if> <if test="category != null"> #{category,jdbcType=VARCHAR}, </if> <if test="type != null"> #{type,jdbcType=INTEGER}, </if> <if test="createTime != null"> #{createTime,jdbcType=TIMESTAMP}, </if> <if test="updateTime != null"> #{updateTime,jdbcType=TIMESTAMP}, </if> <if test="keywords != null"> #{keywords,jdbcType=VARCHAR}, </if> <if test="description != null"> #{description,jdbcType=VARCHAR}, </if> <if test="customer != null"> #{customer,jdbcType=VARCHAR}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="net.ifok.ocms.business.model.Article"> update article <set> <if test="title != null"> title = #{title,jdbcType=VARCHAR}, </if> <if test="image != null"> image = #{image,jdbcType=VARCHAR}, </if> <if test="url != null"> url = #{url,jdbcType=VARCHAR}, </if> <if test="content != null"> content = #{content,jdbcType=VARCHAR}, </if> <if test="contentText != null"> content_text = #{contentText,jdbcType=VARCHAR}, </if> <if test="category != null"> category = #{category,jdbcType=VARCHAR}, </if> <if test="type != null"> type = #{type,jdbcType=INTEGER}, </if> <if test="createTime != null"> create_time = #{createTime,jdbcType=TIMESTAMP}, </if> <if test="updateTime != null"> update_time = #{updateTime,jdbcType=TIMESTAMP}, </if> <if test="keywords != null"> keywords = #{keywords,jdbcType=VARCHAR}, </if> <if test="description != null"> description = #{description,jdbcType=VARCHAR}, </if> <if test="customer != null"> customer = #{customer,jdbcType=VARCHAR}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="net.ifok.ocms.business.model.Article"> update article set title = #{title,jdbcType=VARCHAR}, image = #{image,jdbcType=VARCHAR}, url = #{url,jdbcType=VARCHAR}, content = #{content,jdbcType=VARCHAR}, content_text = #{contentText,jdbcType=VARCHAR}, category = #{category,jdbcType=VARCHAR}, type = #{type,jdbcType=INTEGER}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP}, keywords = #{keywords,jdbcType=VARCHAR}, description = #{description,jdbcType=VARCHAR}, customer = #{customer,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} </update> </mapper> 以上为mybaties generator生成的代码。 $title(ArticleExtMapper.xml) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="net.ifok.ocms.business.mapper.ext.ArticleExtMapper"> <resultMap id="BaseResultMap" type="net.ifok.ocms.business.model.Article" extends="net.ifok.ocms.business.mapper.ArticleMapper.BaseResultMap"> </resultMap> <select id="getLast" resultMap="BaseResultMap"> select * FROM article where type=${type} and id <![CDATA[ < ]]> #{id} order by id desc limit 1 </select> <select id="getNext" resultMap="BaseResultMap"> select * FROM article where type=#{type} and id <![CDATA[ > ]]>#{id} order by id asc limit 1 </select> <select id="getList" resultMap="BaseResultMap"> SELECT * from article where 1=1 and type=#{type} <if test="title!=null"> and title like CONCAT(CONCAT('%', #{title}), '%') </if> <if test="category !=null and category !=''"> and category=#{category} </if> order by create_time desc </select> </mapper> 以上为扩展查询事项说明:ArticleMapper中有,ArticleExtMapper.xml中没有,ArticleExtMapper沿用ArticleMapper中的定义ArticleMapper中有,ArticleExtMapper.xml中也有,ArticleExtMapper使用ArticleExtMapper.xml中的定义ArticleMapper中没有,ArticleExtMapper.xml中有,ArticleExtMapper使用ArticleExtMapper.xml中的定义  ResultMap覆盖Mapper.xml继承机制只针对statement有效,对于sql、resultMap是无效的。如果要在ArticleExtMapper.xml中覆盖这些,必须要先覆盖ParentMapper.xml中的statement,然后让这些statement使用新的sql、resultMap等。总结通过上面的将扩展的部分分开来写,后续改表,生成部分的代码直接覆盖即可,不担心扩展的不见了,二使用的时候直接使用扩展的mapper即可,扩展的mapper包含所有的方法。over ,Enjoy​​​​​​​
  • JDBC 批处理

    JDBC 批处理查询/新增/修改的使用。虽然在一般的编码中不会直接使用jdbc的批处理,但是作为了解记录下来。<h2>前言</h2> JDBC 批处理查询/新增/修改的使用。虽然在一般的编码中不会直接使用jdbc的批处理,但是作为了解记录下来。 <h2>编码记录</h2> JDBC批处理的使用 <pre> <code class="language-java">package org.xqlee.utils.database; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.Statement; /** * * * <pre> * _________________________INFO_____________________________ * | Description : [JDBC批处理的使用] * | Encoding : [UTF-8] * | Package : [org.xqlee.utils.database] * | Project : [utils] * | Author : [LXQ] * | CreateDate : [2016年6月7日上午9:57:33] * | Updater : [] * | UpdateDate : [] * | UpdateRemark: [] * | Company : [Shallink Electronic Information] * | Version : [v 1.0] * | Libs : [] * __________________________________________________________ * </pre> */ public class BatchSQL { public static void main(String[] params) { // statementBatch(); preparedStatementBatch(); } /** * @说明 采用statement方式,不进行预编译 <BR/> * @优点 能针对不同类型的sql语句进行批处理<BR/> * @缺点 语句没进行预编译 * @场景 执行多条不同的sql语句,如新增,更新同时进行的情况 */ public static void statementBatch() { Connection conn = null; Statement st = null; try { // 得到数据库连接 conn = new DBManager("test").getConnection(); conn.setAutoCommit(false); st = conn.createStatement(); String sql = ""; sql = "insert into test_batch values('1111','2222','33333')"; st.addBatch(sql); sql = "insert into test_batch values('1111','4444','4444')"; st.addBatch(sql); sql = "update test_batch set a='0000'"; st.addBatch(sql); st.executeBatch(); conn.commit(); st.clearBatch(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (st != null) { st.close(); st = null; } if (conn != null) { conn.close(); conn = null; } } catch (Exception e2) { // 忽略 } } } /** * @说明 采用PreparedStatement进行预编译的方式执行批处理<BR/> * @优势 采用了预编译sql,执行效率高<BR/> * @缺点 只能处理sql语句相同但参数不同的批处理当中<BR/> * @场景 批量新增,批量更新 */ public static void preparedStatementBatch() { Connection conn = null; PreparedStatement ps = null; try { // 得到数据库连接 conn = new DBManager("test").getConnection(); conn.setAutoCommit(false); String sql = "insert into test_batch values(?,?,?)"; ps = conn.prepareStatement(sql); for (int i = 0; i < 10; i++) { ps.setString(1, i + "A"); ps.setString(2, i + "B"); ps.setString(3, i + "C"); ps.addBatch(); } ps.executeBatch(); conn.commit(); ps.clearBatch(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (null != ps) { ps.close(); ps = null; } if (null != conn) { conn.close(); conn = null; } } catch (Exception e2) { // 忽略 } } } } </code></pre>
  • Java中SAMBA协议文件上传下载

    Java中SAMBA协议文件上传下载 <pre> <code class="language-java">package org.xqlee.utils.samba; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import jcifs.smb.SmbException; import jcifs.smb.SmbFile; import jcifs.smb.SmbFileInputStream; import jcifs.smb.SmbFileOutputStream; /** * * * <pre> * _________________________INFO_____________________________ * Description : [SAMBA协议文件上传下载] * Encoding : [UTF-8] * Package : [org.xqlee.utils.samba] * Project : [utils] * Author : [LXQ] * CreateDate : [] * Updater : [] * UpdateDate : [] * UpdateRemark: [] * Company : [org.xqlee] * Version : [v 1.0] * lib <br/> * jcifs-1.3.17.jar<br/> * __________________________________________________________ * * * </pre> */ public class SAMBAUtil { /*** * 方法说明:文件下载 * * @param name * <br> * 参数:用户名称[若为匿名,此处null] * @param password * <br> * 参数:用户密码[若为匿名,此处null] * @param host * <br> * 参数:samba主机或IP地址 * @param source * <br> * 参数:源文件或目录路径 * @param target * <br> * 参数:下载存放的本地的文件全路径或者目录 * @throws Exception * <br> * 异常:文件传输中可能遇到的异常 */ public static void download(String name, String password, String host, String source, String target) throws Exception { // samba URL组合 StringBuffer sambaURLBuff = new StringBuffer(); sambaURLBuff.append("samba://"); sambaURLBuff.append(host); sambaURLBuff.append("/"); source = source.replaceAll("\\\\", "/"); sambaURLBuff.append(source); // 创建一个smbFile对象对应远程服务器上的SmbFile SmbFile remoteSmbFile = new SmbFile(sambaURLBuff.toString()); // 判断输入的源是需要传输路径还是文件夹 if (remoteSmbFile.isDirectory()) { // 文件目录传输的情况 downloadDirectory(name, password, host, source, target); } else { // 文件的传输情况 downloadFile(name, password, host, source, target); } } /** * 方法说明:<br> * 通过sambaURL方式下载文件 <br> * 其他说明:<br> * 匿名URL:samba://host//url<br> * 用户URL:samba://name:password@host/url * * @param sambaURL * <br> * 参数:sambaURL路径 * @param target * <br> * 参数:本地下载路径 * @throws Exception * <br> * 异常:文件传输中存在的异常 */ public static void download(String sambaURL, String target) throws Exception { // 参数判定 if (null == sambaURL || "".equals(sambaURL)) { throw new Exception("sambaURL 不能为空!"); } if (null == target || "".equals(target)) { throw new Exception("target 不能为空!"); } SmbFile remoteSmbFile = new SmbFile(sambaURL); if (remoteSmbFile.isDirectory()) { downloadDirectory(sambaURL, target); } else { downloadFile(sambaURL, target); } } /*** * 方法说明:通过sambaURL方式单个文件下载 * * @param sambaURL * <br> * 参数:sambaURL * @param target * <br> * 参数:本地下载文件全路径 * @throws Exception * <br> * 异常:文件传输过程出现的异常 */ private static void downloadFile(String sambaURL, String target) throws Exception { // 参数判定 if (null == sambaURL || "".equals(sambaURL)) { throw new Exception("sambaURL 不能为空!"); } if (null == target || "".equals(target)) { throw new Exception("target 不能为空!"); } // destFile target = target.replaceAll("\\\\", "/"); // 本地存放路径 String destFilePath = target.substring(0, target.lastIndexOf("/")); // 判断路径是否存在 File localPath = new File(destFilePath); if (!localPath.exists() || !localPath.isDirectory()) { // 创建路径 localPath.mkdirs(); } InputStream in = null; OutputStream out = null; // 创建一个smbFile对象对应远程服务器上的SmbFile SmbFile remoteSmbFile = new SmbFile(sambaURL); // 本地文件由本地目录,路径分隔符,文件名拼接而成 File localFile = new File(target); // 打开文件输入流,指向远程的smb服务器上的文件,特别注意,这里流包装器包装了SmbFileInputStream in = new BufferedInputStream(new SmbFileInputStream(remoteSmbFile)); // 打开文件输出流,指向新创建的本地文件,作为最终复制到的目的地 out = new BufferedOutputStream(new FileOutputStream(localFile)); // 缓冲内存 byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); buffer = new byte[1024]; } // 最后关闭流 out.close(); in.close(); } /** * 方法说明:samba文件下载 * * @param name * 参数:用户名称[若为匿名,此处null] * @param password * 参数:用户密码[若为匿名,此处null] * @param host * 参数:samba主机名或IP地址 * @param source * 参数:源文件全路径[samba上文件全路径] * @param target * 参数:目标文件全路径[本地下载的地方文件全路径] * @throws Exception * 异常:传输操作可能存在的异常 */ private static void downloadFile(String name, String password, String host, String source, String target) throws Exception { // 1入参检查 if ((host == null) || ("".equals(host.trim()))) { throw new Exception("Samba服务器HOST不能为空!"); } // 2入参检查 if ((source == null) || ("".equals(source.trim()))) { throw new Exception("Samba服务器远程文件路径不可以为空"); } // 3入参检查 if ((target == null) || ("".equals(target.trim()))) { throw new Exception("本地目录路径不可以为空"); } // samba URL组合 StringBuffer urlBuffer = new StringBuffer(); // 转换源路径中的反斜杠 source = source.replaceAll("\\\\", "/"); // 判断是否为匿名访问 if (null != name && password != null && name.length() > 0) { urlBuffer.append(" smb://"); urlBuffer.append(name); urlBuffer.append(":"); urlBuffer.append(password); urlBuffer.append("@"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(source); } else { urlBuffer.append("samba://"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(source); } System.out.println("SAMBA:" + urlBuffer.toString()); // destFile target = target.replaceAll("\\\\", "/"); // 本地存放路径 String destFilePath = target.substring(0, target.lastIndexOf("/")); // 判断路径是否存在 File localPath = new File(destFilePath); if (!localPath.exists() || !localPath.isDirectory()) { // 创建路径 localPath.mkdirs(); } InputStream in = null; OutputStream out = null; // 创建一个smbFile对象对应远程服务器上的SmbFile SmbFile remoteSmbFile = new SmbFile(urlBuffer.toString()); // 本地文件由本地目录,路径分隔符,文件名拼接而成 File localFile = new File(target); // 打开文件输入流,指向远程的smb服务器上的文件,特别注意,这里流包装器包装了SmbFileInputStream in = new BufferedInputStream(new SmbFileInputStream(remoteSmbFile)); // 打开文件输出流,指向新创建的本地文件,作为最终复制到的目的地 out = new BufferedOutputStream(new FileOutputStream(localFile)); // 缓冲内存 byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); buffer = new byte[1024]; } // 最后关闭流 out.close(); in.close(); } /**** * 方法说明:采用sambaURL方式下载文件夹 * * @param sambaURL * 参数:sambaURL路径 * @param target * 参数:下载到本地的文件路径 * @throws Exception * 异常:文件传输过程中出现的异常 */ private static void downloadDirectory(String sambaURL, String target) throws Exception { // 参数判定 if (null == sambaURL || "".equals(sambaURL)) { throw new Exception("sambaURL 不能为空!"); } if (null == target || "".equals(target)) { throw new Exception("target 不能为空!"); } // 本地路径转换 target = target.replaceAll("\\\\", "/"); // 创建一个smbFile对象对应远程服务器上的SmbFile SmbFile remoteSmbFile = new SmbFile(sambaURL); // 获取文件信息 SmbFile[] sbfs = remoteSmbFile.listFiles(); /** 源文件字符流 **/ StringBuffer srcFileBuffer; /** 目标字符流 **/ StringBuffer destFileBuffer; /** 源文件目录 **/ StringBuffer srcPathBuffer; /** 目标文件目录 **/ StringBuffer destPathBuffer; for (SmbFile f : sbfs) { if (f.isDirectory()) {// 如果是文件夹的情况 // srcPathBuffer = new StringBuffer(); sambaURL = sambaURL.replaceAll("\\\\", "/"); srcPathBuffer.append(sambaURL); srcPathBuffer.append("/"); srcPathBuffer.append(f.getName()); destPathBuffer = new StringBuffer(); target = target.replaceAll("\\\\", "/"); destPathBuffer.append(target); destPathBuffer.append("/"); destPathBuffer.append(f.getName()); // 判断还有文件夹 downloadDirectory(srcPathBuffer.toString(), destPathBuffer.toString()); } else { // 源文件 srcFileBuffer = new StringBuffer(); sambaURL = sambaURL.replaceAll("\\\\", "/"); srcFileBuffer.append(sambaURL); srcFileBuffer.append("/"); srcFileBuffer.append(f.getName()); // 目标 destFileBuffer = new StringBuffer(); target = target.replaceAll("\\\\", "/"); destFileBuffer.append(target); destFileBuffer.append("/"); destFileBuffer.append(f.getName()); // 传输单文件 downloadFile(srcFileBuffer.toString(), destFileBuffer.toString()); } } } /** * 下载某个目录所有文件 * * @param name * 参数:用户名称[若为匿名,此处null] * @param password * 参数:用户密码[若为匿名,此处null] * @param host * 参数:SAMBA远程主机 * @param source * 参数:SAMBA远程路径 * @param target * 参数:本地下载路径 * @throws Exception * 异常:文件传输时异常 */ private static void downloadDirectory(String name, String password, String host, String source, String target) throws Exception { // 1入参检查 if ((source == null) || ("".equals(source.trim()))) { throw new Exception("Samba服务器远程文件路径不可以为空"); } // 2入参检查 if ((target == null) || ("".equals(target.trim()))) { throw new Exception("本地目录路径不可以为空"); } // 3入参检查 if ((host == null) || ("".equals(host.trim()))) { throw new Exception("host不可以为空"); } // 本地路径转换 target = target.replaceAll("\\\\", "/"); // samba URL组合 StringBuffer urlBuffer = new StringBuffer(); // 转换源路径中的反斜杠 source = source.replaceAll("\\\\", "/"); // 判断是否为匿名访问 if (null != name && password != null && name.length() > 0) { urlBuffer.append(" smb://"); urlBuffer.append(name); urlBuffer.append(":"); urlBuffer.append(password); urlBuffer.append("@"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(source); } else { urlBuffer.append("samba://"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(source); } System.out.println("SAMBA:" + urlBuffer.toString()); // 创建一个smbFile对象对应远程服务器上的SmbFile SmbFile remoteSmbFile = new SmbFile(urlBuffer.toString()); // 获取文件信息 SmbFile[] sbfs = remoteSmbFile.listFiles(); /** 源文件字符流 **/ StringBuffer srcFileBuffer; /** 目标字符流 **/ StringBuffer destFileBuffer; /** 源文件目录 **/ StringBuffer srcPathBuffer; /** 目标文件目录 **/ StringBuffer destPathBuffer; for (SmbFile f : sbfs) { if (f.isDirectory()) {// 如果是文件夹的情况 // srcPathBuffer = new StringBuffer(); source = source.replaceAll("\\\\", "/"); srcPathBuffer.append(source); srcPathBuffer.append("/"); srcPathBuffer.append(f.getName()); destPathBuffer = new StringBuffer(); target = target.replaceAll("\\\\", "/"); destPathBuffer.append(target); destPathBuffer.append("/"); destPathBuffer.append(f.getName()); // 判断还有文件夹 downloadDirectory(name, password, host, srcPathBuffer.toString(), destPathBuffer.toString()); } else { // 源文件 srcFileBuffer = new StringBuffer(); source = source.replaceAll("\\\\", "/"); srcFileBuffer.append(source); srcFileBuffer.append("/"); srcFileBuffer.append(f.getName()); // 目标 destFileBuffer = new StringBuffer(); target = target.replaceAll("\\\\", "/"); destFileBuffer.append(target); destFileBuffer.append("/"); destFileBuffer.append(f.getName()); // 传输单文件 downloadFile(name, password, host, srcFileBuffer.toString(), destFileBuffer.toString()); } } } /** * samba上传文件 * * @param name * <br> * 参数:用户名[匿名null] * @param password * <br> * 参数:密码[匿名null] * @param host * <br> * 参数:samba主机名或IP地址 * @param source * <br> * 参数:源文件或目录 * @param target * <br> * 参数:目标文件或目录 * @throws Exception */ public static void upload(String name, String password, String host, String source, String target) throws Exception { // 1入参检查 if ((target == null) || ("".equals(target.trim()))) { throw new Exception("Samba服务器远程目录路径不可以为空"); } // 2入参检查 if ((source == null) || ("".equals(source.trim()))) { throw new Exception("本地文件路径不可以为空"); } // 3入参检查 if ((host == null) || ("".equals(host.trim()))) { throw new Exception("本地文件路径不可以为空"); } // 转换源路径中的反斜杠 source = source.replaceAll("\\\\", "/"); // 转换目标路径 target = target.replaceAll("\\\\", "/"); // 本地路径判断 File localPath = new File(source); if (localPath.isDirectory()) { uploadDirectory(name, password, host, source, target); } else { uploadFile(name, password, host, source, target); } } /** * 方法说明:<br> * 通过sambaURL方式上传文件 <br> * 其他说明:<br> * 匿名URL:samba://host//url<br> * 用户URL:samba://name:password@host/url * * @param source * <br> * 参数:源文件 * @param sambaURL * <br> * 参数:sambaURL路径 * @throws Exception * <br> * 异常:文件传输所产生的异常 */ public static void upload(String source, String sambaURL) throws Exception { if (null == source || "".equals(source)) { throw new Exception("源文件路径不能为空!"); } if (null == sambaURL || "".equals(sambaURL)) { throw new Exception("sambaURL路径不能为空!"); } // 本地路径判断 File localPath = new File(source); if (localPath.isDirectory()) { uploadDirectory(source, sambaURL); } else { uploadFile(source, sambaURL); } } /**** * 方法说明:通过sambaURL方式上传文件 * * @param source * <br> * 参数:需要上传的源文件 * @param sambaURL * <br> * 参数:sambaURL路径 * @throws Exception * <br> * 异常:文件传输过程中遇到的异常问题 */ private static void uploadFile(String source, String sambaURL) throws Exception { if (null == source || "".equals(source)) { throw new Exception("源文件路径不能为空!"); } if (null == sambaURL || "".equals(sambaURL)) { throw new Exception("sambaURL路径不能为空!"); } InputStream in = null; OutputStream out = null; // 判断远程路径是否存在,如果不存在创建目录 /** 远程存放文件路径 **/ String sambaPath = sambaURL.substring(0, sambaURL.lastIndexOf("/")); SmbFile targetSmbFile = new SmbFile(sambaPath); if (!targetSmbFile.exists() || !targetSmbFile.isDirectory()) {// 判断路径是否存在 // 创建目录 targetSmbFile.mkdirs(); } // 处理上传->读取本地文件->上传到samba文件 // 读取本地文件 File localFile = new File(source); // 创建远程服务器上Samba文件对象 SmbFile remoteSmbFile = new SmbFile(sambaURL); // 打开一个文件输入流执行本地文件,要从它读取内容 in = new BufferedInputStream(new FileInputStream(localFile)); // 打开一个远程Samba文件输出流,作为复制到的目的地 out = new BufferedOutputStream(new SmbFileOutputStream(remoteSmbFile)); // 缓冲内存 byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); buffer = new byte[1024]; } // 关闭相应流 out.close(); in.close(); } /** * 方法说明:上传文件到samba路径 * * @param name * 参数:用户名[匿名null] * @param password * 参数:密码[匿名null] * @param host * 参数:主机名或IP * @param source * 参数:源文件,需要上传的文件 * @param target * 参数:目标文件全路径/samba文件路径 * @throws IOException * 异常:抛出异常 */ private static void uploadFile(String name, String password, String host, String source, String target) throws IOException { // 本地路径转换 target = target.replaceAll("\\\\", "/"); // samba URL组合 StringBuffer urlBuffer = new StringBuffer(); // 转换源路径中的反斜杠 source = source.replaceAll("\\\\", "/"); // 判断是否为匿名访问 if (null != name && password != null && name.length() > 0) { urlBuffer.append(" smb://"); urlBuffer.append(name); urlBuffer.append(":"); urlBuffer.append(password); urlBuffer.append("@"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(target); } else { urlBuffer.append("samba://"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(target); } System.out.println("SAMBA:" + urlBuffer.toString()); InputStream in = null; OutputStream out = null; // 判断远程路径是否存在,如果不存在创建目录 /** 远程存放文件路径 **/ String targetPath = urlBuffer.toString().substring(0, urlBuffer.toString().lastIndexOf("/")); SmbFile targetSmbFile = new SmbFile(targetPath); if (!targetSmbFile.exists() || !targetSmbFile.isDirectory()) {// 判断路径是否存在 // 创建目录 targetSmbFile.mkdirs(); } // 处理上传->读取本地文件->上传到samba文件 // 读取本地文件 File localFile = new File(source); // 创建远程服务器上Samba文件对象 SmbFile remoteSmbFile = new SmbFile(urlBuffer.toString()); // 打开一个文件输入流执行本地文件,要从它读取内容 in = new BufferedInputStream(new FileInputStream(localFile)); // 打开一个远程Samba文件输出流,作为复制到的目的地 out = new BufferedOutputStream(new SmbFileOutputStream(remoteSmbFile)); // 缓冲内存 byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); buffer = new byte[1024]; } // 关闭相应流 out.close(); in.close(); } private static void uploadDirectory(String source, String sambaURL) throws Exception { if (null == source || "".equals(source)) { throw new Exception("源文件路径不能为空!"); } if (null == sambaURL || "".equals(sambaURL)) { throw new Exception("sambaURL路径不能为空!"); } // 转换源路径中的反斜杠 source = source.replaceAll("\\\\", "/"); File dir = new File(source); File[] files = dir.listFiles(); /** 源文件字符流 **/ StringBuffer srcFileBuffer; /** 目标字符流 **/ StringBuffer destFileBuffer; /** 源文件目录 **/ StringBuffer srcPathBuffer; /** 目标文件目录 **/ StringBuffer destPathBuffer; for (File f : files) { if (f.isDirectory()) { srcPathBuffer = new StringBuffer(); source = source.replaceAll("\\\\", "/"); srcPathBuffer.append(source); srcPathBuffer.append("/"); srcPathBuffer.append(f.getName()); destPathBuffer = new StringBuffer(); sambaURL = sambaURL.replaceAll("\\\\", "/"); destPathBuffer.append(sambaURL); destPathBuffer.append("/"); destPathBuffer.append(f.getName()); uploadDirectory(srcPathBuffer.toString(), destPathBuffer.toString()); } else { // 源文件 srcFileBuffer = new StringBuffer(); source = source.replaceAll("\\\\", "/"); srcFileBuffer.append(source); srcFileBuffer.append("/"); srcFileBuffer.append(f.getName()); // 目标 destFileBuffer = new StringBuffer(); sambaURL = sambaURL.replaceAll("\\\\", "/"); destFileBuffer.append(sambaURL); destFileBuffer.append("/"); destFileBuffer.append(f.getName()); uploadFile(srcFileBuffer.toString(), destFileBuffer.toString()); } } } /** * 上传目录所有文件到samba * * @param name * 参数:用户名[匿名null] * @param password * 参数:密码[匿名null] * @param host * 参数:samba主机或IP地址 * @param source * 参数:源文件,需要上传的文件或目录 * @param target * 参数:目标文件,需要上传到samba的路径 * @throws IOException * 异常:抛出异常 */ private static void uploadDirectory(String name, String password, String host, String source, String target) throws IOException { // 转换源路径中的反斜杠 source = source.replaceAll("\\\\", "/"); File dir = new File(source); File[] files = dir.listFiles(); /** 源文件字符流 **/ StringBuffer srcFileBuffer; /** 目标字符流 **/ StringBuffer destFileBuffer; /** 源文件目录 **/ StringBuffer srcPathBuffer; /** 目标文件目录 **/ StringBuffer destPathBuffer; for (File f : files) { if (f.isDirectory()) { srcPathBuffer = new StringBuffer(); source = source.replaceAll("\\\\", "/"); srcPathBuffer.append(source); srcPathBuffer.append("/"); srcPathBuffer.append(f.getName()); destPathBuffer = new StringBuffer(); target = target.replaceAll("\\\\", "/"); destPathBuffer.append(target); destPathBuffer.append("/"); destPathBuffer.append(f.getName()); uploadDirectory(name, password, host, srcPathBuffer.toString(), destPathBuffer.toString()); } else { // 源文件 srcFileBuffer = new StringBuffer(); source = source.replaceAll("\\\\", "/"); srcFileBuffer.append(source); srcFileBuffer.append("/"); srcFileBuffer.append(f.getName()); // 目标 destFileBuffer = new StringBuffer(); target = target.replaceAll("\\\\", "/"); destFileBuffer.append(target); destFileBuffer.append("/"); destFileBuffer.append(f.getName()); uploadFile(name, password, host, srcFileBuffer.toString(), destFileBuffer.toString()); } } } /** * 方法说明:获取samba目录中的所有文件信息 * * @param name * <br> * 参数:用户名[匿名null] * @param password * <br> * 参数:密码[匿名null] * @param host * <br> * 参数:samba主机或IP地址 * @param path * <br> * 参数:samba上需要获取信息的路径 * @return 返回:List<br> * Map k-v:<br> * K-name :文件名<br> * K-lastModified:自1970.1.1到修改时刻的秒数<br> * K-path:文件所在samba路径<br> * * @throws MalformedURLException * 异常 * @throws SmbException * 异常 */ public static List<Map<String, Object>> sambaFileListInfo(String name, String password, String host, String path) throws MalformedURLException, SmbException { // samba URL组合 StringBuffer urlBuffer = new StringBuffer(); // 转换源路径中的反斜杠 path = path.replaceAll("\\\\", "/"); // 判断是否为匿名访问 if (null != name && password != null && name.length() > 0) { urlBuffer.append(" smb://"); urlBuffer.append(name); urlBuffer.append(":"); urlBuffer.append(password); urlBuffer.append("@"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(path); } else { urlBuffer.append("samba://"); urlBuffer.append(host); urlBuffer.append("/"); urlBuffer.append(path); } System.out.println("SAMBA:" + urlBuffer.toString()); // 获取samba上的文件信息 SmbFile sf = new SmbFile(urlBuffer.toString()); // 获取文件列表 SmbFile[] sfs = sf.listFiles(); // 创建一个map的list集合,用于返回数据 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map; for (SmbFile f : sfs) { if (f.isDirectory()) { // path StringBuffer pathBuffer = new StringBuffer(); pathBuffer.append(path); pathBuffer.append("/"); pathBuffer.append(f.getName()); pathBuffer.append("/"); List<Map<String, Object>> ls = sambaFileListInfo(name, password, host, pathBuffer.toString()); list.addAll(ls); } else { map = new HashMap<String, Object>(); map.put("name", f.getName()); map.put("lastModified", f.getLastModified()); map.put("path", f.getPath()); list.add(map); } } return list; } /** * 通过sambaURL方式获取目录下文件信息 * * @param sambaURL * 参数 * @return 返回: * @throws MalformedURLException * @throws SmbException */ public static List<Map<String, Object>> sambaFileListInfo(String sambaURL) throws MalformedURLException, SmbException { sambaURL = sambaURL.replaceAll("\\\\", "/"); sambaURL = sambaURL + "/"; // 获取samba上的文件信息 SmbFile sf = new SmbFile(sambaURL); // 获取文件列表 SmbFile[] sfs = sf.listFiles(); // 创建一个map的list集合,用于返回数据 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map; for (SmbFile f : sfs) { if (f.isDirectory()) { // path StringBuffer pathBuffer = new StringBuffer(); pathBuffer.append(sambaURL); pathBuffer.append("/"); pathBuffer.append(f.getName()); pathBuffer.append("/"); List<Map<String, Object>> ls = sambaFileListInfo(pathBuffer.toString()); list.addAll(ls); } else { map = new HashMap<String, Object>(); map.put("name", f.getName()); map.put("lastModified", f.getLastModified()); map.put("path", f.getPath()); list.add(map); } } return list; } } </code></pre>
  • idea 生成vo对象的setter对字符串加trim()

    一、配置idea setter模板首先 按快捷键   Alt+Insert 弹出generater 对话框​弹出对话框​点击箭头指的位置,弹出以下内容:​上面首先点击绿色的‘+’号添加一个模板,名称为 trimSetter,模板内容为红色框一、配置idea setter模板首先 按快捷键   Alt+Insert 弹出generater 对话框​弹出对话框​点击箭头指的位置,弹出以下内容:​上面首先点击绿色的‘+’号添加一个模板,名称为 trimSetter,模板内容为红色框内的,下面以文本方式给大家方便复制:#set($paramName = $helper.getParamName($field, $project)) #if($field.modifierStatic) static ## #end void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) { #if ($field.name == $paramName) #if (!$field.modifierStatic) this.## #else $classname.## #end #end $field.name = ## #if($field.string) $paramName == null ? null : $paramName.## trim(); #else $paramName; #end }模板创建完成后点击 ok按钮返回之前的页面,然后在setter 模板的地方选择我们刚才创建的模板 trimSetter,如下图:​接下来,选择字段进行生成,生成效果如下:public class ApplyDataWord { String applyName; String info; public String getApplyName() { return applyName; } public void setApplyName(String applyName) { this.applyName = applyName == null ? null : applyName.trim(); } public String getInfo() { return info; } public void setInfo(String info) { this.info = info == null ? null : info.trim(); } }​​​​​​​搞定,收工;
  • java 以http client的post/get方式访问指定url

    java 以http client的post/get方式访问指定url <pre> <code class="language-java"> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; import com.xqlee.dev.project.core.utils.io.IOUtil; /** * * * <pre> * _________________________INFO_____________________________ * | Description : [HTTP客服端] * | Encoding : [UTF-8] * | Package : [org.xqlee.utils.net] * | Project : [utils] * | Author : [] * | CreateDate : [] * | Updater : [] * | UpdateDate : [] * | UpdateRemark: [] * | Company : [Shallink Electronic Information] * | Version : [v 1.0] * | Libs : [] * __________________________________________________________ * </pre> */ public class HttpClient { public static String doGet(String url, String param) throws IOException { String result = ""; BufferedReader in = null; try { String urlNameString = url + "?" + param; URL realUrl = new URL(urlNameString); // 打开和URL之间的连接 URLConnection connection = realUrl.openConnection(); // 设置通用的请求属性 connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 建立实际的连接 connection.connect(); // 获取所有响应头字段 Map<String, List<String>> map = connection.getHeaderFields(); // 遍历所有的响应头字段 for (String key : map.keySet()) { System.out.println(key + "--->" + map.get(key)); } // 定义 BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));// 防止乱码 String line; while ((line = in.readLine()) != null) { result += line; result+=IOUtil.LINE_SEPARATOR; } } catch (IOException e) { throw e; } finally { try { if (in != null) { in.close(); } } catch (Exception e2) { throw e2; } } return result; } public static String doPost(String url, String param) throws IOException { PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL realUrl = new URL(url); // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 发送POST请求必须设置如下两行 conn.setDoOutput(true); conn.setDoInput(true); // 获取URLConnection对象对应的输出流 out = new PrintWriter(conn.getOutputStream()); // 发送请求参数 out.print(param); // flush输出流的缓冲 out.flush(); // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); String line; while ((line = in.readLine()) != null) { result += line; result+=IOUtil.LINE_SEPARATOR; } } catch (IOException e) { throw e; } finally { try { if (out != null) { out.close(); } if (in != null) { in.close(); } } catch (IOException ex) { throw ex; } } return result; } } </code></pre>