![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
纯真-Cloud
愿纯真依旧!
展开
-
解决IntelliJ IDEA运行时报错:找不到符号 log
前提:gradle springboot项目解决:配置Plugins中安装lombok;配置中打开annotation processing:Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable annotation processingbuild.gradle中添加:implementation ‘org.projectlombok:lombok:1.18.20’原创 2021-08-03 14:33:55 · 1357 阅读 · 0 评论 -
解决io.lettuce.core.RedisCommandExecutionException: ERR hash value is not an integer问题
执行操作:redisTemplate.opsForHash().put(“TEST", “7”, 2L);查看redis中的数据: 1) "7" 2) "\xac\xed\x00\x05sr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x0原创 2021-06-25 18:10:32 · 2987 阅读 · 0 评论 -
通过配置的方式实现类似SQL方式查询MongoDB
背景说明对于Mysql,有灵活的sql语句直接执行,且sql语句对于程序来说即一个字符串,很方便扩展或变换,即使是有变量,也可以通过字符串操作直接实现替换,最重要的是sql结构比较简单易懂,而且天生适合关联查询。而MongoDB操作起来就不那么方便,没有sql,必须同时熟悉javascript语言语法和mongo命令、参数,如果不熟悉的话,则要在代码里写死查询框架,不方便修改和扩展。这里通过java实现了一个类似sql的语言框架,采取json格式,以方便通过配置的方式实现mongo查询。代码实现查询主原创 2020-06-17 15:10:57 · 578 阅读 · 1 评论 -
Elasticsearch(ES)多条件过滤实现案例
要完成上述图片上的查询条件,也即需要同时符合多种过滤条件。由于公司的服务器中安装的elasticsearch版本很老,升级不是很方便,所以是基于老版本,新版本相应的语句做一些改变也可以。实现:(具体条件需要更改)(elasticsearch版本:2.3.2)实现代码潜在优化:1. "should": [ {"match_...原创 2018-06-20 15:56:39 · 23665 阅读 · 2 评论 -
Springboot http session支持分布式;同时支持 cookie 和 header 传递;websocket 连接 共享 http session
这里有三个问题:1. http session支持分布式;2. session 同时支持 cookie 和 header 传递;3. websocket 连接 共享 http session。对于第一个问题,很简单:implementation 'org.springframework.boot:spring-boot-starter-data-redis'implemen...原创 2020-03-27 15:23:50 · 2235 阅读 · 0 评论 -
Error during WebSocket handshake: Unexpected response code: 200 错误解决
项目中配置了支持sockjs:stompEndpointRegistry // ------------------------------------------------------------------ .addEndpoint("/stomp") // 将/serviceName/stomp/websocket路径注册为STOMP的端点 .setAllowedOrigins(...原创 2020-03-21 19:40:34 · 6385 阅读 · 0 评论 -
对于Websocket发送消息时,报错“TEXT_FULL_WRITING”的一种解决方案
import java.nio.ByteBuffer;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.CopyOnWriteArraySet;import java.util.concurrent.Future;import javax.websocket.Session;impor...原创 2019-07-05 10:22:21 · 11920 阅读 · 5 评论 -
eclipse gradle springboot 打印单元测试日志
在eclipse中运行Gradle Tasks - test,是不会打印logger.debug等日志的,解决方法:直接在你想要运行的单元测试文件右键,配置Run Configurations - Project Settings - Program Arguments,填写--debug,然后直接点右下角的Run...原创 2019-05-24 11:09:30 · 785 阅读 · 0 评论 -
eclipse gradle springboot lombok 使用
1. eclipse gradle lombok报错:找不到符号解决方案:File - Settings - Build - Compiler - Annotation Processors 中勾选Enable annotation processing 后确认。gradle.build:dependencies { // https://projectlombok.or...原创 2019-02-03 13:37:37 · 870 阅读 · 2 评论 -
Learning Java
1. 获取一个对象指定field(无论是否是private,包括父类中的属性) import org.apache.commons.lang3.reflect.FieldUtils;FieldUtils.getField(clazz, propertyName, true);需import jar包:org.apache.commons:commons-lang3 2. 创...原创 2018-12-12 14:00:08 · 123 阅读 · 0 评论 -
通过@PropertySource和@ConfigurationProperties来加载(读取)自定义配置文件
在项目中,习惯用YAML来写配置文件,但读取自定义配置文件时,遇到了问题:编写两个配置文件:1. temp.ymlprefix: what: x list: - name: tech item: 123 - name: skill item: 9872. temp.propertiesprefix.what = xprefi...原创 2018-12-21 16:19:06 · 4647 阅读 · 0 评论 -
使用@ConditionalOnProperty控制是否加载
public interface OSService { void os();}@ConditionalOnProperty(prefix = "custom.os", name = "name", havingValue = "linux")@Service("osService")public class LinuxService implements OSService...原创 2018-12-20 18:39:44 · 3928 阅读 · 3 评论 -
使用PageHelper实现SpringBoot项目中对查询结果的分页
1. 引入依赖compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.2.10')2. 将分页逻辑单独拎出来实现public class PageUtility { public static PageSerializable<?> search(MyPage myPage, Object re...原创 2018-12-20 15:08:37 · 2320 阅读 · 0 评论 -
使用Springboot @TypeDiscriminator注解实现多态对象的查询,jackson @JsonTypeInfo注解实现controller多态支持
背景:最近项目中涉及到要实现继承对象的获取,由于习惯用注解实现mybatis对象映射,所以也想用@TypeDiscriminator实现。但是在百度中却搜索不到@TypeDiscriminator的应用实例,幸好能上国外网,Google之。下面以一个最简单的例子来讲@TypeDiscriminator用法。例子:有五个对象,Person,Teacher,Student,Answer,S...原创 2018-12-05 17:03:43 · 4626 阅读 · 0 评论 -
Java中static关键字用法总结
1. 静态方法 通常,在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法 声明为static的方法有以下几条限制: · 它们仅能调用其他的static 方法。 · 它们只能访问static数据。 · 它们不能以任何方式引用this 或super。class Simple { static void go() {转载 2017-05-10 17:08:35 · 218 阅读 · 0 评论