Home

Spring BeanWrapper操作对象属性

代码实例 UserCorpusStat userCorpusStat = new UserCorpusStat(userId, corpusId); BeanWrapper userCorpusStatBeanWrapper = new BeanWrapperImpl(userCorpusStat); Integer count = (Integer)userCorpusStatBeanWrapper.getPropertyValue(userCorpusStatCountField); userCorpusStatBeanWrapper.setPropertyValue(userCorpusStatCountField, 1);

Read more

MyBatis-Plus自定义InnerInterceptor使用

代码实例 实现一个InnerInterceptor,对所有SQL进行拦截处理 public class DeletedFilterInterceptor implements InnerInterceptor { @Override @SneakyThrows // 拦截select查询语句,对语句作处理 public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { String sql = bo...

Read more

MySQL group_concat函数例子

SQL例子 SELECT t_book.id, t_book.chinese_name, t_book.name, group_concat(t_author.chinese_name separator '/') from t_book_author left join t_author on t_author.id = t_book_author.author_id left join t_book on t_book.id = t_book_author.book_id group by t_book.id, t_book.chinese_name, t_book.name; group_concat可看作为聚集函数,把目标字段的字符串连接起来,可指定分隔符

Read more

Java父类与子类的变量与方法的关系

知识总结 子类会继承父类的所有变量与方法,但不一定可见。反射机制可访问不可见的变量以及方法。 对于子类来说,不可见的父类变量或方法虽然被继承下来,但无法直接访问,方法也无法重写。即使父类与子类存在同名的变量或方法,事实上并不会产生关联。(static也一样) 对于可见的变量或方法,若子类并没有覆盖,可以子类的访问方式直接访问父类的变量以及方法。若子类已覆盖,则以子类的访问方式访问到的是子类覆盖后的变量以及方法。(static也一样) 只有可见的父类变量或方法,可以使用super访问

Read more

MyBatis-Plus代码生成器使用

Maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.5.3</v...

Read more

Java主要容器类特点总结

接口 Collection 可以放入多个同类型的对象 List 继承Collection接口,容器内对象有序 Set 继承Collection接口,容器内对象不可重复 Queue 继承Collection接口,容器内对象有序,且实现了队列先进先出的特性 Deque 继承Queue接口,实现了双端队列 BlockingQueue 继承Queue接口,实现了阻塞式入队和出队 Map 实现key到value之间的映射 实现类 非线程安全 ArrayList 实现List接口,数据结构为动态扩容的对象数组 LinkedList 实现List接口和Deque接口,数据结构为双向链表 HashSet 实现Set接口,底层为HashMap ...

Read more

Spring Boot配置文件中获取Maven信息

代码实例 application.yml odm: system: version: '@project.version@' chinese-name: '@project.description@' 可获取Maven的pom.xml文件中的配置项 当yml配置文件中出现中文时,配置文件的字符编码配置不当会导致项目启动报错,最好都统一为UTF-8

Read more

JUnit运行Spring容器内测试

代码例子 Spring项目 使用JUnit 4 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = WebConfig.class) public class RootControllerTest { } Spring Boot项目 使用JUnit 5 @SpringBootTest class LanguageTrainerApplicationTests { @Test void contextLoads() { } }

Read more

ThreadLocal使用

带初始值 public class SimpleDateFormatUtil { private static final ThreadLocal<SimpleDateFormat> simpleDateFormatThreadLocal = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMdd HH:mm:ss")); public static SimpleDateFormat getSimpleDateFormat() { return simpleDateFormatThreadLocal.get(); } } 不带初...

Read more