Spring Boot编程式事务
无需处理返回值
注入TransactionTemplate
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(@NotNull TransactionStatus status) {
if(!checkUserLoginLogExistence(localDate)) {
UserLoginStat userLoginStat = getUserLoginStat(userId);
Inte...
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...
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...
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',\
...
Cobertura生成单元测试覆盖率报告
配置Maven插件
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<go...
MySQL获取数据库表定义
获取表定义信息
select * from information_schema.tables;
获取表字段定义信息
select * from information_schema.columns;
Git远端仓库删除文件,保留本地文件
代码例子
git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master
方法是删掉本地缓存文件,然后提交到本地仓库, push到远程仓库
Git关联GitHub远程仓库实例
代码例子
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/Still1/still-context.git
git push -u origin master
Eclipse Terminal CMD命令指定初始路径
操作步骤
Eclipse设置
Arguments设置
/k h:&&cd programming/run/eclipseEE/Still1/still-core
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
332 post articles, 34 pages.