配置openOffice
下载 tar.gz 包。下载地址:http://www.openoffice.org/zh-cn/ (需要下载 rpm 格式的)
通过 xftp 上传到 linux 中。我的目录在/opt/openoffice 中
解压文件:tar -zxvf Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz,解压后进入 zh-CN 目录中。
cd RPMS/ 里面都是 rpm 文件,我们需要安装这些文件
安装 rpm 文件: rpm -ivh *.rpm
进入 desktop-integration/目录:cd desktop-integration/
安装 openoffice:rpm -ivh openoffice4.1.6-redhat-menus-4.1.6-9790.noarch.rpm
安装成功后会在/opt 下出现一个 openoffice4 文件。
启动服务
/opt/openoffice4/program/soffice -headless -accept="socket,host=127.0 ...
Linux下文档类型转PDF乱码解决方式
在 Linux 系统下进行文本类型转 PDF 时出现乱码。
解决方案:
安装 fontconfig
安装命令:
yum –y install fontconfig
在/usr/share/fonts 目录下新建一个目录 chinese
操作命令:
cd /usr/share/fonts
mkdir chinese
cd chinese
修改文件夹权限
操作命令:
chmod -R 755 /usr/share/fonts/chinese/
将本地字体上传至服务器
操作步骤:
将 C:\Windows\Fonts 目录下的字体拷贝到一个新建文件夹(因为文件夹权限无法直接上传,所以需要创建一个新建文件夹)
将需要的字体上传到服务器的/usr/share/fonts/chinese 目录下
安装 ttmkfdir
安装命令:
yum -y install ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
修改 fonts.conf 配置文件
操作命令:
vi /etc/fonts/fonts.c ...
中国大陆镜像源
http://mirrors.aliyun.com/ubuntu
rabbitmq-server管理
前提:通信端口默认是 5672 端口,如果远程连接,别忘记先在防火墙上开启该端口
查看运行状态
service rabbitmq-server status启动
service rabbitmq-server stop
停止
service rabbitmq-server start
重启 rabbitmq 服务
service rabbitmq-server restart
查看 log 文件
cd /var/log/rabbitmq/
vim ***.log
查看已有插件列表
rabbitmq-plugins list
安装插件(这里以安装 web 管理客户端为例子,该客户端的端口是 15672.别忘记在防火墙开启端口)rabbitmq-plugins enable rabbitmq_management
编写配置文件(这里以开放外部访问为例子)cd /etc/rabbitmq/vim rabbitmq.config
向 rabbitmq.config 文件中写入如下内容:[{rabbit, [{loopback_users, []}]}].
传输文件显示permission denied
scp 默认不允许使用 root 账号传输文件.如果想用 root 账号传输文件,在两端服务器
0、使用第二步切换为 root 账号
1、修改 sshd 配置文件
vi /etc/ssh/sshd_config
2、找到 PermitRootLogin,把前面的#去掉,并且改为 yes
PermitRootLogin yes
3、重启 sshd 服务
service ssh start
4、使用 root 账户远程登陆服务器并传输文件即可。注意 root 密码是在第二步自己设置的
没有firewall-cmd命令
apt-get updateapt-get install firewalld
安装nginx
# 切换至root用户sudo su rootapt-get install nginx
查看 nginx 是否安装成功
nginx -v
启动 nginx
service nginx start #方式1/usr/sbin/nginx #方式2
结束 nginx
service nginx stop #方式1/usr/sbin/nginx -s stop #方式2
重启 nginx
service nginx reload #方式1/usr/sbin/nginx -s reload #方式2
注意:nginx 方式 1 和方式 2 不能互相调用
nginx 文件安装完成之后的文件位置:
/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志
设置静态ip
ubuntu_server18vim /etc/netplan/50-cloud-init.yaml
配置如下,注意格式 冒号后边有个空格
network: ethernets: ens33: dhcp4: false addresses: [192.168.37.188/24] gateway4: 192.168.37.2 nameservers: addresses: [114.114.114.114, 8.8.8.8] version: 2
编辑好 最后保存配置文件,执行命令重启网络服务生效
sudo netplan applys
切换为root账号
Ubuntu 的默认 root 密码是随机的,即每次开机都有一个新的 root 密码。可以在终端输入命令 sudo passwd,然后输入当前用户的密码,回车.
终端会提示输入新的密码并确认,此时的密码就是 root 新密码。修改成功后,输入命令 su root,再输入新的密码就成功切换到 root 帐号了
事务的传播行为以及在spring中的配置
一、什么是事务传播行为?事务传播行为(propagation behavior)指的就是当一个事务方法被另一个事务方法调用时,这个事务方法应该如何运行。
例如:methodA 方法调用 methodB 方法时,methodB 是继续在调用者 methodA 的事务中运行呢,还是为自己开启一个新事务运行,这就是由 methodB 的事务传播行为决定的。
二、事务的 7 种传播行为Spring 在 TransactionDefinition 接口中规定了 7 种类型的事务传播行为。事务传播行为是 Spring 框架独有的事务增强特性。7 种:(required / supports / mandatory / requires_new / not supported / never / nested)
PROPAGATION_REQUIRED:如果当前没有事务,就创建一个新事务,如果当前存在事务,就加入该事务,这是最常见的选择,也是 Spring 默认的事务传播行为。(required 需要,没有新建,有加入)
PROPAGATION_SUPPORTS:支持当前事务,如果当前存在事务, ...
解决cookie跨域问题
业务需求:当前网站想要访问第三方网站的页面,第三方网站的页面接口都需要使用 cookie 认证授权遇到的问题:当前网站和第三方网站不同域。在当前网站使用 iframe。跳转到第三方时。后台通过接口得到的 cookie 无法传递
解决方式 1:nginx 反向代理,用当前网站的域代理第三方网站,然后用当前网站的域+第三方网站的接口 url 就能获取第三方网站的页面或数据示例:nginx.conf
server { listen 19100; #server_name localhost; location / { proxy_pass http://47.95.34.252:8084; } }
js
const url = 'http://127.0.0.1:19100/JcjcGl/Dcztjctky/Dcztbx'function initPage() { $.ajax({ url: Hussar.ctxPat ...
使用poi导出带有数据的模版
@Overridepublic void downloadLjcjImportTemplate(String xianbie, String xingbie, HttpServletResponse response) { // 设置返回头 response.setHeader( "Content-disposition", "attachment;filename=" + new String(("路基u型槽沉降模版.xlsx").getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1)); // 从库里查询数据 QueryWrapper<TTzCjDmjcd> qw = new QueryWrapper<>(); qw.eq("xianbie", xianbie); qw.eq("xingbie", xingbie); qw.eq("jcd_ ...
使用java代码控制事务
代码中控制事务的三种方式
编程式事务:就是直接在代码里手动开启事务,手动提交,手动回滚。优点就是可以灵活控制,缺点就是太麻烦了,太多重复的代码了。
声明式事务:就是使用 SpringAop 配置事务,这种方式大大的简化了编码。需要注意的是切入点表达式一定要写正确。
注解事务:直接在 Service 层的方法上面加上@Transactional 注解,个人比较喜欢用这种方式。
事务回滚的原因
在工作中,看过别人写的代码出现了事务不回滚的现象。当然,事务不回滚的都是采用的声明式事务或者是注解事务;编程式事务都是自己写代码手动回滚的,因此是不会出现不回滚的现象。
再说下声明式事务和注解事务回滚的原理:当被切面切中或者是加了注解的方法中抛出了 RuntimeException 异常时,Spring 会进行事务回滚。默认情况下是捕获到方法的 RuntimeException 异常,也就是说抛出只要属于运行时的异常(即 RuntimeException 及其子类)都能回滚;但当抛出一个不属于运行时异常时,事务是不会回滚的。
下面说说我经常见到的 3 种事务不回滚的产生原因:
(1)声明式 ...
使用注解和拦截器实现登录验证
1、@LoginRequired 注解/** * 在需要登录验证的Controller的方法上使用此注解 */@Target({ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)public @interface LoginRequired {}
2、MyControllerAdvice@ControllerAdvicepublic class MyControllerAdvice { @ResponseBody @ExceptionHandler(TokenValidationException.class) public JsonResponse tokenValidationExceptionHandler() { return JsonResponse.loginInvalid(); } @ResponseBody @ExceptionHandler(ServiceException.class) ...
文件下载与预览
通常的文件下载方法@RequestMapping("/downLoadFile")public void downLoadLineStruImportTemplateFile(HttpServletResponse response) { // 创建缓冲区 byte buffer[] = new byte[1024];// 缓冲区大小1k int len = 0; // 重点就是获取输入流和输出流,还有设置请求头 try (InputStream in = this.getClass().getClassLoader().getResourceAsStream("template/lineStruImportTemplate.xlsx"); OutputStream out = response.getOutputStream()) { // 设置头部信息 // 文件类型application/octet-stream response.s ...
检查文件是否存在
/** * 下载文件,传入完成路径,先检查文件是否存在,如果存在就下载 * @param path */downloadFileWithPath = function (path) { $.ajax({ url: Hussar.ctxPath + '/checkFileExist', type: 'get', async: true, data: { path }, success(res) { if (res.code === 500) { Hussar.valid(res.msg) return } // 如果文件存在,那么就下载文件 window.location.href = '/downLoadFile?path=' + path }, error() { Hussar.valid(' ...
整合druid不支持批量更新的问题
轻骑兵的解决方式
注意 url 后面多了个 allowMultiQueries=true
spring: ################### mysql配置 ################### datasource: url: jdbc:mysql://123.123.122.138:3310/dtjc_sbgl_dev?autoReconnect=true&rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2b8&allowMultiQueries=true username: root password: 123456a? db-name: dtjc_sbgl_dev filters: log4j,mergeStat driverClassName: com ...
动态加载服务器上的图片
<img src="/loadImg?path='xxx'" />
/** * IO流读取存在服务器上的图片 * * @return * @throws IOException */@RequestMapping(value = "/loadImg", method = RequestMethod.GET)public void loadImg(@RequestParam("path") String path, HttpServletResponse response) throws IOException { //这里省略掉通过id去读取图片的步骤。 File file = new File(path);//imgPath为服务器图片地址 if (file.exists() && file.isFile()) { FileInputStream in = null; Ou ...
获取resouces下的文件的输入流InputStream
String filePath = "/excel/1_20210709杭州地铁6号线平稳性_2021_08_28_005001_5S.xlsx";// 这里io流会自动关闭,无需加finally// try (InputStream is = new FileInputStream(filePath)) {// 读取绝对路径文件ClassPathResource classPathResource = new ClassPathResource(filePath);try (InputStream is = classPathResource.getInputStream()) {// 读取resources下文件方式1(适用于静态)// try (InputStream is = this.getClass().getResourceAsStream(filePath)) {// 读取相resources下文件方式2(不适用于静态) // ....流对象各种处理代码}
获取相对路径下的配置文件信息
路径位置如下
配置文件信息
ureport.disableFileProvider=falseureport.debug=trueureport.disableHttpSessionReportCache=falseureport.fileStoreDir=D:/hussar/hussar_v8/hussar-web/src/main/resources/ureportfiles/odmsfilePath = D:/DevelopKit/FILEopenOfficePath = D:/Program Files (x86)/OpenOffice 4/program/soffice.exe -headless -accept="socket,host=127.0.0.1,port=8100;urp;"pdfPath = D:/PDF/fpPath = D:/fenpianpythonPath = D:/pythoncode/dataReaderName = DWDataReaderLib64.dll
代码示例
package com.jxdinfo.hussar.ut ...