Home

Spring Boot编程式事务

无需处理返回值 注入TransactionTemplate transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(@NotNull TransactionStatus status) { if(!checkUserLoginLogExistence(localDate)) { UserLoginStat userLoginStat = getUserLoginStat(userId); Inte...

Read more

Mockito静态方法mock

依赖配置 取消Spring Boot默认的mockito-core依赖,转变为依赖mockito-inline pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <exclusions> <exclusion> <groupId>org.mockito</groupId> &l...

Read more

Spring MVC RESTful全局异常处理

代码实例 package com.oliverclio.languagetrainer.wrap; import lombok.Data; @Data public class ResponseEntity { public static final String SUCCESS_MESSAGE = "OK"; private String message; private Object data; private ResponseEntity() { } public static ResponseEntity wrapDataResponseEntity(Object...

Read more

Spring MVC使用properties配置

代码实例 在root上下文配置类上加上注解@PropertySource @Configuration @PropertySource({ "classpath:properties/database.properties", "classpath:properties/path.properties" }) public class RootConfig { } path.properties picturesPath=/greenbean/pictures/ database.properties greenbean.db={\ driverClassName : 'com.mysql.cj.jdbc.Driver',\ ...

Read more

Maven安装最佳实践

安装步骤 下载Maven安装压缩包,并解压 设置环境变量M2_HOME 示例:C:\still1\run\apache-maven-3.3.9-bin\apache-maven-3.3.9 设置环境变量path,示例:%M2_HOME%\bin 设置环境变量MAVEN_OPTS,示例:-Xms128m -Xmx512m -Dfile.encoding=UTF-8 复制用户settings.xml 示例 C:\still1\run\apache-maven-3.3.9-bin\apache-maven-3.3.9\conf\settings.xml 复制到 C:\Users\Still1\.m2\settings.xml

Read more