您好,登錄后才能下訂單哦!
/**
* SponsorApplication for 廣告贊助商/投遞服務(wù)啟動(dòng)類
* 添加注解{@link EnableFeignClients}之后,當(dāng)前微服務(wù)就可以調(diào)用別的微服務(wù),
* 但是當(dāng)前服務(wù)是廣告提供,不需要調(diào)用別的微服務(wù),在此只是為了在dashboard中監(jiān)控
* {@link EnableCircuitBreaker} 也是為了dashboard監(jiān)控
*
* @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
* @since 2019/6/15
*/
@EnableDiscoveryClient //開啟服務(wù)發(fā)現(xiàn)Eureka Client
@EnableCircuitBreaker //開啟斷路器
@EnableFeignClients //開啟feign client,使其可以通過HTTP調(diào)用其他微服務(wù)
@SpringBootApplication
public class SponsorApplication {
public static void main(String[] args) {
SpringApplication.run(SponsorApplication.class, args);
}
}
server:
port: 7000
servlet:
context-path: /ad-sponsor #http請(qǐng)求的根路徑(請(qǐng)求前綴,在handle的mapping之前,需要127.0.0.1/ad-sponsor/XXXX)
spring:
application:
name: mscx-ad-sponsor
jpa:
show-sql: true #執(zhí)行時(shí)是否打印sql語句,方便調(diào)試
hibernate:
ddl-auto: none
properties:
hibernate.format_sql: true
open-in-view: false #控制是否在懶加載時(shí),有可能會(huì)找不到bean報(bào)錯(cuò)
datasource:
username: ***
url: jdbc:mysql://127.0.0.1:3306/advertisement?useSSL=false&autoReconnect=true
password: ***
tomcat:
max-active: 4 #最大連接數(shù)
min-idle: 2 #最小空閑連接數(shù)
initial-size: 2 #默認(rèn)初始化連接數(shù)
eureka:
client:
service-url:
defaultZone: http://server1:7777/eureka/,http://server2:8888/eureka/,http://server3:9999/eureka/
實(shí)體類和數(shù)據(jù)庫(kù)表一般是一一對(duì)應(yīng),通常稱之為entity
,以用戶表為例:Lombok傳送門
/**
* AdUser for 數(shù)據(jù)庫(kù)ad_user表對(duì)應(yīng)的實(shí)體類
* {@link Basic} 標(biāo)示為數(shù)據(jù)庫(kù)的字段信息,如果需要一個(gè)不屬于數(shù)據(jù)庫(kù)的字段,標(biāo)注為 {@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 //不寫的話,默認(rèn)就是@Basic,表示是數(shù)據(jù)庫(kù)表的一個(gè)字段
//@Transient //如果打上@Transient 注解,表明當(dāng)前字段不是表中的字段
@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;
/**
* 創(chuàng)建用戶時(shí)所需的必填字段
*
* @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 通用狀態(tài)枚舉
*
* @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
*/
@Getter
public enum CommonStatus {
VALID(1, "有效"),
INVALID(0, "無效狀態(tài)");
private Integer status;
private String desc;
CommonStatus(Integer status, String desc) {
this.status = status;
this.desc = desc;
}
}
其他的數(shù)據(jù)庫(kù)對(duì)應(yīng)實(shí)體類(AdUnit
,AdPlan
,AdCreative
,AdUnitDistrict
,AdUnitHobby
,AdUnitKeyword
,RelationshipCreativeUnit
),大家可以參考上面的例子自己實(shí)現(xiàn),也可以去github上下載源碼。
做一個(gè)好人。
博客園 | segmentfault | spring4all | csdn | 掘金 | OSChina | 簡(jiǎn)書 | 頭條 | 知乎 | 51CTO
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。