实操经验总结(零散知识点)
工作中实际操作经验的总结记录
ZmyCoder
该博客作为学习笔记使用。
展开
-
idea的mapper.xml文件里写sql语句出现Tag name expected错误提示
原因是:xml文件的某些特殊字符是自动转义的, xml解析器会忽视CDATA中的内容原创 2022-06-02 16:45:15 · 960 阅读 · 0 评论 -
@Transactional注解的失效场景
参考@Transactional注解的失效场景1、@Transactional 应用在非 public 修饰的方法上如果Transactional注解应用在非public 修饰的方法上,Transactional将会失效。之所以会失效是因为在Spring AOP 代理时,如上图所示 TransactionInterceptor (事务拦截器)在目标方法执行前后进行拦截,DynamicAdvisedInterceptor(CglibAopProxy 的内部类)的 intercept 方法或 JdkDy转载 2021-06-09 12:23:30 · 98 阅读 · 0 评论 -
Springboot 多模块启动Services
在IDEA开发工具快捷键Ctrl+Shift+A,输入services效果图在此services窗口显示所有的Spring boot 项目,方便项目启动、停止转载 2021-04-01 18:08:37 · 1056 阅读 · 0 评论 -
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
扫描不到mapper.xml文件。检查mybatis.mapper-locations的配置路径是否正确。原创 2021-04-01 15:58:00 · 109 阅读 · 0 评论 -
Springboot中@Aspect无法引入
解决方法:在pom文件中引入下面两个依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> <scope>test</scope> </dependency> <depende原创 2021-03-03 20:31:42 · 1161 阅读 · 1 评论 -
MySql Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts‘
MySql Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’ 解决方法环境:linux,mysql5.5.21错误:Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’原因:同一个ip在短时间内产生太多(超过mysql数据库max_connection转载 2021-03-03 12:24:31 · 1196 阅读 · 0 评论 -
MyBatis-Plus的IPage分页total不正确问题
场景:执行了一条连接查询的sql语句,进行分页后,total不正确问题。如下图:分析:分页部分代码如下:String sql = searchSqlBuilderInstance.generateSql();Page page = new Page(commonSearchDTO.getPageAndTableInfo().getPageNum(),commonSearchDTO.getPageAndTableInfo().getPageSize());IPage<Map<Str原创 2021-02-25 14:21:19 · 9937 阅读 · 7 评论 -
idea启动springboot项目控制台报错Command line is too long. Shorten command line for xxx or also for Spring B解决
错误:Error running ‘xxx项目’: Command line is too long. Shorten command line for xxx or also for Spring Boot default configuration.解决方案:1.在IDEA中找到 Run-> Edit Configurations打开2.在 Environment-> Shorten command line 的内容配置为 JAR即可解决:...转载 2021-02-23 09:13:48 · 1653 阅读 · 0 评论 -
@JsonFormat时间格式化注解使用
@JsonFormat注解是一个时间格式化注解,比如我们存储在mysql中的数据是date类型的,当我们读取出来封装在实体类中的时候,就会变成英文时间格式,而不是yyyy-MM-dd HH:mm:ss这样的中文时间,因此我们需要用到JsonFormat注解来格式化我们的时间。JsonFormat注解是jackson包里面的一个注解,因此在使用的时候需要引入fasterxml maven的jar包,如下所示。<dependency> <groupId>com.fasterx转载 2021-01-25 09:42:17 · 194 阅读 · 0 评论 -
Java关于throw和throws
在网上找了很多例子,但还不是很清楚,有几点疑惑、所以自己做了下实验。首先推荐一篇文章,写的很好。Java运行时异常和非运行时异常实验一:主测试类public class Main { public static void main(String[] args) { ThrowClass throwClass = new ThrowClass(); try { throwClass.test1(0); }catc原创 2021-01-22 19:08:50 · 600 阅读 · 2 评论 -
swagger如何传递Object类型的数据?
如题,某类中有一个Object类型的属性,该类作为controller层参数时,如何传递?@Data@AllArgsConstructor@NoArgsConstructorpublic class FilterConditionValue { private String id; private Object value;}测试controller方法如下:@PostMapping("test")@ApiOperation(value = "test")@Api原创 2021-01-22 15:03:48 · 2465 阅读 · 1 评论 -
Java检查字符串是否是合法的日期格式
代码如下: /** * 检查日期格式是否合法 * * @param str 日期字符串 * @return boolean */ private static boolean isValidDate(String str) { boolean convertSuccess = true; // 指定日期格式为四位年/两位月份/两位日期,注意yyyy/MM/dd区分大小写,可扩展到时分秒; Simple原创 2021-01-22 11:16:13 · 555 阅读 · 0 评论 -
springboot中没有主清单属性解决办法
问题:XXX.jar中没有主清单属性解决办法根本原因:打包后的jar中的MANIFEST.MF文件缺少Main-Class解决方法:在pom.xml文件中添加: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId&g转载 2021-01-18 09:57:48 · 256 阅读 · 0 评论 -
java web实现文件下载功能
1.新建Servlet文件,可以命名为DownloadServlet,映射url是“/downloadServlet”,我的项目名称是suiningAdmissions;2.在DownloadServlet中加入以下内容,其中filename是你在下载的时候需要传递的参数,是你即将下载的文件的名称;package cn.itIcey.suining.web.servlet;import javax.servlet.ServletException;import javax.servlet.anno原创 2021-01-15 17:42:59 · 502 阅读 · 3 评论 -
idea中SpringBoot项目自动部署----devtools
1、导入pom依赖<!--springboot自动部署devtools--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</o原创 2021-01-15 09:48:45 · 148 阅读 · 0 评论 -
javax.websocket.server.ServerContainer not available
在SpringBoot项目中集成了WebSocket,在进行单元测试的时候,出现了以下错误:javax.websocket.server.ServerContainer not available单元测试类的原注解是这样的:@RunWith(SpringRunner.class)@SpringBootTest经查阅资料,得知SpringBootTest在启动的时候不会启动服务器,所以WebSocket自然会报错,这个时候需要添加选项webEnvironment,以便提供一个测试的web环境。如转载 2021-01-11 17:46:10 · 263 阅读 · 2 评论 -
must be unique: xxx.xxx.xxx:xxx:jar -> duplicate declaration of version 0.0.1 @ line 25, column 21
maven在package打包时报的警告:(groupId:artifactId:type:classifier)' must be unique: com.zmy:common:jar -> duplicate declaration of version经检查,common重复引用。解决方法:保留一个引用即可。原创 2021-01-07 14:38:32 · 6138 阅读 · 0 评论 -
idea中使用easy code
使用easy code配置mybatis plus模板。可根据个性化需求进行相应更改。1、安装插件settings->plugins->搜索easy code,安装下图插件。重启生效。2、配置模板2.1、新建分组mybatisplus2.2、添加各类文件内容如下。可根据具体需求自定义。entity##引入宏定义$!define##使用宏定义设置回调(保存位置与文件后缀)#save("/entity", ".java")##使用宏定义设置包后缀#setPac原创 2021-01-05 18:09:41 · 214 阅读 · 0 评论 -
Failed to execute goal org.apache.,maven.plug...问题
Failed to execute goal org.apache.,maven.plugins:maven-compiler-plugin:3.8.1问题解决方法在pom.xml文件中修改版本。原创 2020-11-16 18:54:48 · 275 阅读 · 0 评论 -
Java链式调用方式
之前接入支付宝支付接口的时候,看到支付宝提供的demo中有这么一段代码:// 创建扫码支付请求builder,设置请求参数 AlipayTradePrecreateRequestBuilder builder = new AlipayTradePrecreateRequestBuilder() .setSubject(subject)//订单主题 .setTotalAmount(totalAmount)//订单总金额,单位为元转载 2021-01-05 10:32:26 · 4341 阅读 · 1 评论 -
cannot deserialize from Object value (no delegate- or property-based Creator)
postman请求后,报错:cannot deserialize from Object value (no delegate- or property-based Creator)解决方法:controller层的参数,增加无参构造函数原创 2021-01-04 14:20:31 · 356 阅读 · 0 评论 -
Mybatis 当实体属性与数据库字段不一致时的解决方案
Mybatis会根据相同的属性和字段名通过set方法进行注入,那如果实体类的属性名和数据库的字段名不相同呢?方法一:通过修改sql语句修改映射文件中的sql语句:测试结果:说明:可以发现Mybatis是根据查询出来的字段名去找实体类相对的属性去注入。方法二:添加关联映射在映射文件中加入关联映射,如下:测试结果如下:总结:两种方法都可以解决实体属性和数据库字段不一致的问题,不过一般都是使用第二种,通过添加关联映射来解决该问题。...转载 2020-12-24 12:58:45 · 861 阅读 · 0 评论 -
Java调试程序运行时间
Java 获取并计算程序执行时间,有以下两种方法:(1)以毫秒为单位计算 static long currentTimeMillis() , 该方法返回值是从1970年1月1日凌晨到此时刻的毫秒数 long startTime=System.currentTimeMillis(); //获取开始时间 doSomeThing(); //测试的代码段 long endTime=System.currentTimeMillis(); //获取结束时间 System.out.println("转载 2020-12-24 12:49:35 · 492 阅读 · 0 评论 -
mysql:distinct, group by 去重用法和区别
问题描述查询数据经常需要对数据表的某一属性进行去重操作,group by 和 distinct 都有去重功能,但是有区别。一.数据去重样例样例数据表 quancheng_testidname1a2b3c4d5a6b功能需求:按 name 进行去重,把 id 查出来。方案1:select id from quancheng_test group by name;结果id1234方案转载 2020-12-24 12:46:24 · 184 阅读 · 0 评论 -
Hutool工具包Excel工具使用
一、导入依赖<!-- hutool工具类依赖--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.4.3</version></dependency><!--POI依赖,对office进行操作--><dependency><gro转载 2020-12-23 20:43:51 · 4667 阅读 · 3 评论 -
Mybatis使用ResultMap对应查询结果和实体类时,对应关系混乱。
Mybatis使用ResultMap对应查询结果和实体类时,对应关系混乱。原因:实体类同时使用@Data和@Builder两个注解@Data@Builderpublic class ActBusRelVo {<resultMap id="ActBusRelVoMap" type="com.tongfun.module.yanwu.stream.entity.vo.ActBusRelVo"> <result column="action_suggestion"原创 2020-12-10 16:07:45 · 541 阅读 · 2 评论 -
Spring Boot Configuration Annotation Processor not found in claspath
导入配置文件:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>原创 2020-12-08 11:25:53 · 45 阅读 · 0 评论 -
idea添加方法注释
step1step2step3step4* * @Description: $description$ * @Param: $params$ * @return: $returns$ * @Author: zhangmy * @Date: $date$ */step5选中Everywherestep6使用方法:/*a + Enter效果:原创 2020-12-04 17:11:32 · 205 阅读 · 0 评论 -
Linux中部署SpringBoot项目的脚本
脚本内容(build.sh):#!/bin/shexport JAVA_HOME=/usr/local/jdk-11.0.8/jdk-11.0.8export PATH=$JAVA_HOME/bin:$PATHexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/libecho "find uniform pid"pids=`ps aux | grep uniform`echo $pidsOLD_IFS="$IFS"IFS=" "array=原创 2020-12-04 10:51:55 · 97 阅读 · 0 评论 -
Mysql中,使用group by报错
使用Mysql的group by报错原文:https://www.cnblogs.com/chancy/p/10026097.htmlsql语句如下:SELECT table_id, description FROM bos_table_description GROUP BY table_id报错信息:SELECT list is not in GROUP BY clause and contains nonaggregated column ‘cy_form.bos_table_d转载 2020-12-03 16:46:27 · 777 阅读 · 0 评论 -
maven仓库中已经拷贝好jar包,但是还是报错
cannot resolve XXX:XXX原文:https://blog.csdn.net/ztx114/article/details/72528608解决方法:方法1找到jar包所在文件夹,删除掉.repositories和.lastUpdated文件,然后update方法2maven中的本地仓库的index索引没有更新导致在eclipse中打开菜单 window-> show view –> other –> Maven -> maven reposit转载 2020-12-03 16:12:01 · 727 阅读 · 0 评论 -
gateway启动报错
gateway启动报错Parameter 0 of method modifyResponseBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type ‘org.springframework.http.codec.ServerCodecConfigurer’ that could not be found.问题如下图:解决原创 2020-12-01 15:18:38 · 586 阅读 · 0 评论 -
idea中application.yaml未识别为小叶子
idea中application未识别为小叶子step1step2step3step4step5step6、完成原创 2020-12-01 15:00:22 · 260 阅读 · 0 评论 -
权限控制
基于角色访问控制基于角色访问控制,即为RBAC(Role-Based Access Control)。用户表角色表权限表用户角色表:为用户绑定角色角色权限表:为角色赋予权限原创 2020-11-25 21:25:03 · 97 阅读 · 0 评论 -
Maven父子工程
Maven父子工程建立1、建立父工程建立maven项目父工程pom配置文件(选择自己需要的jar依赖)<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/P原创 2020-11-04 10:30:34 · 291 阅读 · 0 评论