[Spring cloud 一步步實現廣告系統] 5. 投放系統配置+啓動+實體類

廣告投放系統啓動主類說明
/**
 * SponsorApplication for 廣告贊助商/投遞服務啓動類
 * 添加註解{@link EnableFeignClients}以後,當前微服務就能夠調用別的微服務,
 * 可是當前服務是廣告提供,不須要調用別的微服務,在此只是爲了在dashboard中監控
 * {@link EnableCircuitBreaker} 也是爲了dashboard監控
 *
 * @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
 * @since 2019/6/15
 */
@EnableDiscoveryClient //開啓服務發現Eureka Client
@EnableCircuitBreaker //開啓斷路器
@EnableFeignClients //開啓feign client,使其能夠經過HTTP調用其餘微服務
@SpringBootApplication
public class SponsorApplication {
    public static void main(String[] args) {
        SpringApplication.run(SponsorApplication.class, args);
    }
}
配置信息
server:
  port: 7000
  servlet:
    context-path: /ad-sponsor #http請求的根路徑(請求前綴,在handle的mapping以前,須要127.0.0.1/ad-sponsor/XXXX)
spring:
  application:
    name: mscx-ad-sponsor
  jpa:
    show-sql: true #執行時是否打印sql語句,方便調試
    hibernate:
      ddl-auto: none
    properties:
      hibernate.format_sql: true
    open-in-view: false #控制是否在懶加載時,有可能會找不到bean報錯
  datasource:
    username: ***
    url: jdbc:mysql://127.0.0.1:3306/advertisement?useSSL=false&autoReconnect=true
    password: ***
    tomcat:
      max-active: 4 #最大鏈接數
      min-idle: 2 #最小空閒鏈接數
      initial-size: 2 #默認初始化鏈接數
eureka:
  client:
    service-url:
      defaultZone: http://server1:7777/eureka/,http://server2:8888/eureka/,http://server3:9999/eureka/
建立實體對象

實體類和數據庫表通常是一一對應,一般稱之爲entity,以用戶表爲例:Lombok傳送門html

/**
 * AdUser for 數據庫ad_user表對應的實體類
 * {@link Basic} 標示爲數據庫的字段信息,若是須要一個不屬於數據庫的字段,標註爲 {@link Transient}
 *
 * @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
 * @since 2019/6/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "ad_user")
public class AdUser {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id", nullable = false)
    private Long userId;

    @Basic //不寫的話,默認就是@Basic,表示是數據庫表的一個字段
  	//@Transient //若是打上@Transient 註解,代表當前字段不是表中的字段
    @Column(name = "user_name", nullable = false)
    private String userName;

    @Basic
    @Column(name = "token", nullable = false)
    private String token;

    @Basic
    @Column(name = "user_status", nullable = false)
    private Integer userStatus;

    @Basic
    @Column(name = "create_time", nullable = false)
    private Date createTime;

    @Basic
    @Column(name = "update_time", nullable = false)
    private Date updateTime;

    /**
     * 建立用戶時所需的必填字段
     *
     * @param user_name 用戶名稱
     * @param token     token
     */
    public AdUser(String user_name, String token) {
        this.userName = user_name;
        this.token = token;
        this.userStatus = CommonStatus.VALID.getStatus();
        this.createTime = new Date();
        this.updateTime = this.createTime;
    }
}

---
/**
 * CommonStatus for 通用狀態枚舉
 *
 * @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
 */
@Getter
public enum CommonStatus {
    VALID(1, "有效"),
    INVALID(0, "無效狀態");

    private Integer status;
    private String desc;

    CommonStatus(Integer status, String desc) {
        this.status = status;
        this.desc = desc;
    }
}

其餘的數據庫對應實體類(AdUnit,AdPlan,AdCreative,AdUnitDistrict,AdUnitHobby,AdUnitKeyword,RelationshipCreativeUnit),你們能夠參考上面的例子本身實現,也能夠去github上下載源碼。java


作一個好人。

博客園 | segmentfault | spring4all | csdn | 掘金 | OSChina | 簡書 | 頭條 | 知乎 | 51CTOmysql

相關文章
相關標籤/搜索