• Somthing about Spring Boot


    Auditor

    @Configuration
    public class CommonConfiguration implements AuditorAware<String> {
    
        /**
         * Get current auditor
         * @return Auditor Optional object
         */
        @Override
        public Optional<String> getCurrentAuditor() {
            //Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            //if (authentication == null) {
            //    return Optional.of("Unknown");
            //} else if (!authentication.isAuthenticated()) {
            //    return Optional.of("Unauthenticated");
            //} else {
            //    UserDetails userDetails = (UserDetails) authentication.getPrincipal();
            //    return Optional.of(userDetails.getUsername());
            //}
            return Optional.of("system");
        }
    }
    

    Fucking Lombok...

    /**
     * For database auditing
     * Could not audit remove operating
     *
     * @author seliote
     * @since 2019-10-19
     */
    // Designates its child class applied the mapping info, and had no separate table defined for it
    @MappedSuperclass
    // Enable auto @PrePersist & @PreUpdate
    @EntityListeners(AuditingEntityListener.class)
    // Hibernate change delete sql before execute, there could not get table name
    public class Auditable {
    
        // Row create user
        @CreatedBy
        @Column(name = "create_user")
        private String createUser;
    
        // Row create date
        @CreatedDate
        @Column(name = "create_date")
        private LocalDateTime createDate;
    
        // Row modify user
        @LastModifiedBy
        @Column(name = "modify_user")
        private String modifyUser;
    
        // Row modify date
        @LastModifiedDate
        @Column(name = "modify_date")
        private LocalDateTime modifyDate;
    
        // Delete mark, this field could auto audit, should manual update in every entity
        @Column(name = "delete_mark")
        private boolean deleteMark;
    
        public String getCreateUser() {
            return createUser;
        }
    
        public void setCreateUser(String createUser) {
            this.createUser = createUser;
        }
    
        public LocalDateTime getCreateDate() {
            return createDate;
        }
    
        public void setCreateDate(LocalDateTime createDate) {
            this.createDate = createDate;
        }
    
        public String getModifyUser() {
            return modifyUser;
        }
    
        public void setModifyUser(String modifyUser) {
            this.modifyUser = modifyUser;
        }
    
        public LocalDateTime getModifyDate() {
            return modifyDate;
        }
    
        public void setModifyDate(LocalDateTime modifyDate) {
            this.modifyDate = modifyDate;
        }
    
        public boolean isDeleteMark() {
            return deleteMark;
        }
    
        public void setDeleteMark(boolean deleteMark) {
            this.deleteMark = deleteMark;
        }
    }
    

    JPA annotation should in FIELD not GETTER, otherwise the method extended named get... will also mapping to database column

    /**
     * Admin entity
     *
     * @author seliote
     * @since 2019-10-19
     */
    @Entity
    @Table(name = "admin")
    @Where(clause = "delete_mark = 0")
    @SQLDelete(sql = "UPDATE `admin` SET `delete_mark` = 1 WHERE `uuid` = ?")
    public class AdminEntity extends Auditable implements UserDetails {
    
        // Admin uuid, primary key
        @Id
        @Column(name = "uuid")
        private String uuid;
    
        // Admin name, login name
        @Column(name = "user")
        private String user;
    
        // Admin password, login password
        @Column(name = "password")
        private String password;
    
        public String getUuid() {
            return uuid;
        }
    
        public void setUuid(String uuid) {
            this.uuid = uuid;
        }
    
        public String getUser() {
            return user;
        }
    
        public void setUser(String user) {
            this.user = user;
        }
    
        @Override
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        @Override
        public Collection<? extends GrantedAuthority> getAuthorities() {
            // Grant ADMIN authority
            return Arrays.asList(new SimpleGrantedAuthority(Constant.Security.Authority.ADMIN));
        }
    
        @Override
        public String getUsername() {
            return getUser();
        }
    
        @Override
        public boolean isAccountNonExpired() {
            return true;
        }
    
        @Override
        public boolean isAccountNonLocked() {
            return true;
        }
    
        @Override
        public boolean isCredentialsNonExpired() {
            return true;
        }
    
        @Override
        public boolean isEnabled() {
            return true;
        }
    }
    

    Property

    This line defualt in application.properties, otherwise need @PropertySource

    com.seliote.productId=666
    

    Could inject this component to other bean and use getter

    /**
     * Inject all properties
     *
     * @author seliote
     * @since 2019-10-20
     */
    @Component
    @ConfigurationProperties(prefix = "com.seliote")
    public class PropertyConfiguration {
        private String productId;
    
        public String getProductId() {
            return productId;
        }
    
        public void setProductId(String productId) {
            this.productId = productId;
        }
    }
    

    HTTPS

    server:
      # for embed Tomcat...
      port: 8443
      ssl:
        key-store: classpath:cert/demo.jks
        key-password: drowssap321
        key-store-password: drowssap123
    
  • 相关阅读:
    尚学堂 JAVA DAY12 概念总结
    A new classification algorithm recommendation method based on link prediction
    MLE & MAP
    Performance Measurement
    Stacking
    SVM
    I/O Multiplexing
    Bomb Lab
    ABOUT
    题目集概况 题目列表 提交列表 排名 共 60 分 编程题 (共 60 分) PAT 线上测试赛真题(2020-05-01)
  • 原文地址:https://www.cnblogs.com/seliote/p/11741204.html
Copyright © 2020-2023  润新知