Commit ccb66224 authored by zengtianlai3's avatar zengtianlai3

2.3.7 异常处理:finally代码块中抛出异常

parent 8ebd2e59
...@@ -45,11 +45,15 @@ public class TcpServer { ...@@ -45,11 +45,15 @@ public class TcpServer {
f.channel().closeFuture().sync(); f.channel().closeFuture().sync();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
log.error("Tcp服务异常,端口:{}",port); log.error("Tcp服务异常,端口:{}", port);
}finally { } finally {
log.debug("Tcp服务,停止退出"); log.debug("Tcp服务,停止退出");
workerGroup.shutdownGracefully(); if (workerGroup != null) {
bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully();
}
if (bossGroup != null) {
bossGroup.shutdownGracefully();
}
} }
} }
}); });
......
...@@ -22,7 +22,7 @@ public class ResourceManager { ...@@ -22,7 +22,7 @@ public class ResourceManager {
@Autowired @Autowired
ResourceService resourceService; ResourceService resourceService;
public void downloadDeviceInfoExcle(HttpServletResponse response, int userId) throws IOException { public void downloadDeviceInfoExcle(HttpServletResponse response, int userId){
OutputStream os = null; OutputStream os = null;
HSSFWorkbook wb = null; HSSFWorkbook wb = null;
try { try {
...@@ -113,13 +113,21 @@ public class ResourceManager { ...@@ -113,13 +113,21 @@ public class ResourceManager {
} }
wb.write(os); wb.write(os);
} catch (IOException e) { } catch (IOException e) {
log.error("Excel表格信息下载异常,{}",e.getMessage()); log.error("Excel表格信息下载异常,{}", e.getMessage());
} finally { } finally {
if (os != null) { if (os != null) {
os.close(); try {
os.close();
} catch (IOException e) {
log.error("Excel表格信息下载异常,{}", e.getMessage());
}
} }
if (wb != null) { if (wb != null) {
wb.close(); try {
wb.close();
} catch (IOException e) {
log.error("Excel表格信息下载异常,{}", e.getMessage());
}
} }
} }
} }
......
package iot.sixiang.license.util;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
public class CodeGenerator {
public static void main(String[] args) {
// 1、创建代码生成器
AutoGenerator mpg = new AutoGenerator();
// 2、全局配置
GlobalConfig gc = new GlobalConfig();
// String projectPath = System.getProperty("user.dir");
gc.setOutputDir("D:\\zengtianlai\\test2\\ioc_sixiang_license\\license" + "/src/main/java");
gc.setAuthor("lai");
gc.setOpen(false); //生成后是否打开资源管理器
gc.setFileOverride(false); //重新生成时文件是否覆盖
gc.setServiceName("%sService"); //去掉Service接口的首字母I
mpg.setGlobalConfig(gc);
// 3、数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("123456");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 4、包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName("license"); //模块名
pc.setParent("iot.sixiang");
pc.setController("controller");
pc.setEntity("entity");
pc.setService("service");
pc.setMapper("mapper");
mpg.setPackageInfo(pc);
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setInclude("sys_oper_log");
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
strategy.setRestControllerStyle(true); //restful api风格控制器
strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
mpg.setStrategy(strategy);
// 6、执行
mpg.execute();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment