-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhengjiaao
committed
Apr 15, 2024
1 parent
a97db4e
commit 30bef48
Showing
104 changed files
with
6,473 additions
and
197 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
starter-data/starter-data-jpa/src/main/java/com/zja/JpaApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2022-02-14 10:59 | ||
* @Since: | ||
*/ | ||
package com.zja; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
|
||
/** | ||
* http://localhost:8080/swagger-ui/index.html#/ | ||
* @swagger3: <a href="http://localhost:8080/swagger-ui/index.html">...</a> | ||
* @author: zhengja | ||
* @since: 2023/08/10 13:18 | ||
*/ | ||
@SpringBootApplication | ||
public class JpaApplication { | ||
public class JpaApplication extends SpringBootServletInitializer { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(JpaApplication.class, args); | ||
} | ||
|
||
} | ||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
return application.sources(JpaApplication.class); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
starter-data/starter-data-jpa/src/main/java/com/zja/audit/AuditUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2023-09-28 12:32 | ||
* @Since: | ||
*/ | ||
package com.zja.audit; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author: zhengja | ||
* @since: 2023/09/28 12:32 | ||
*/ | ||
@Data | ||
public class AuditUser { | ||
private String userId; | ||
private String userName; | ||
} |
50 changes: 50 additions & 0 deletions
50
starter-data/starter-data-jpa/src/main/java/com/zja/audit/AuditorAwareImplA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2023-09-27 17:27 | ||
* @Since: | ||
*/ | ||
package com.zja.audit; | ||
|
||
import com.zja.util.IdGeneratorUtil; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author: zhengja | ||
* @since: 2023/09/27 17:27 | ||
*/ | ||
public class AuditorAwareImplA implements AuditorAware<String> { | ||
|
||
@Override | ||
public Optional<String> getCurrentAuditor() { | ||
|
||
//模拟当前登录用户 | ||
AuditUser currentUser = new AuditUser(); | ||
currentUser.setUserId(IdGeneratorUtil.objectId()); //当前用户id | ||
currentUser.setUserName("李四"); | ||
|
||
if (ObjectUtils.isEmpty(currentUser)) { | ||
return Optional.empty(); | ||
} | ||
|
||
//一般项目中从spring security或token中获取 | ||
return Optional.of(currentUser.getUserId()); | ||
} | ||
|
||
//示例:从Spring Security中获取当前用户名 | ||
/* private String getUserName() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
if (authentication == null || !authentication.isAuthenticated()) { | ||
return Optional.empty(); | ||
} | ||
String username = authentication.getName(); | ||
return username; | ||
}*/ | ||
} |
32 changes: 32 additions & 0 deletions
32
starter-data/starter-data-jpa/src/main/java/com/zja/audit/AuditorAwareImplB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2023-09-27 17:27 | ||
* @Since: | ||
*/ | ||
package com.zja.audit; | ||
|
||
import com.zja.util.IdGeneratorUtil; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author: zhengja | ||
* @since: 2023/09/27 17:27 | ||
*/ | ||
public class AuditorAwareImplB implements AuditorAware<String> { | ||
|
||
@Override | ||
public Optional<String> getCurrentAuditor() { | ||
//当前用户id | ||
String currentUserId = IdGeneratorUtil.objectId(); | ||
|
||
//一般从项目请求token中获取当前登录用户 | ||
return StringUtils.hasText(currentUserId) ? Optional.of(currentUserId) : Optional.of("system"); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
starter-data/starter-data-jpa/src/main/java/com/zja/audit/JpaAuditingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @Company: 上海数慧系统技术有限公司 | ||
* @Department: 数据中心 | ||
* @Author: 郑家骜[ào] | ||
* @Email: [email protected] | ||
* @Date: 2023-09-27 17:24 | ||
* @Since: | ||
*/ | ||
package com.zja.audit; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
/** | ||
* @author: zhengja | ||
* @since: 2023/09/27 17:24 | ||
*/ | ||
@Configuration | ||
//@EnableJpaAuditing | ||
@EnableJpaAuditing(auditorAwareRef = "auditorProviderB") //若注册了多个实现,则通过 auditorAwareRef=“”进行选择 | ||
public class JpaAuditingConfig { | ||
|
||
@Bean("auditorProviderA") | ||
public AuditorAware<String> auditorProviderA() { | ||
return new AuditorAwareImplA(); | ||
} | ||
|
||
@Bean("auditorProviderB") | ||
public AuditorAware<String> auditorProviderB() { | ||
return new AuditorAwareImplB(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.