[Spring cloud realizes advertising system step by step] 5. Playing system configuration + boot + entity class

Keywords: Java Database SQL Hibernate Spring

Main Class Description for Starting Advertising Playing System
/**
 * SponsorApplication for Advertising Sponsor/Delivery Service Startup Class
 * After adding the annotation {@link EnableFeignClients}, other microservices can be invoked by the current microservice.
 * However, the current service is provided by advertisements, and no other micro services need to be invoked. This is just for monitoring in dashboard.
 * {@link EnableCircuitBreaker} It's also for dashboard monitoring
 *
 * @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
 * @since 2019/6/15
 */
@EnableDiscoveryClient //Open service discovery Eureka Client
@EnableCircuitBreaker //Open circuit breaker
@EnableFeignClients //Open feign client to invoke other micro services over HTTP
@SpringBootApplication
public class SponsorApplication {
    public static void main(String[] args) {
        SpringApplication.run(SponsorApplication.class, args);
    }
}
configuration information
server:
  port: 7000
  servlet:
    context-path: /ad-sponsor #Root path of http request (request prefix, 127.0.0.1/ad-sponsor/XXXX before mapping of handle)
spring:
  application:
    name: mscx-ad-sponsor
  jpa:
    show-sql: true #Whether or not to print sql statements when executing to facilitate debugging
    hibernate:
      ddl-auto: none
    properties:
      hibernate.format_sql: true
    open-in-view: false #Controlling whether bean s are not found to report errors when lazy loading occurs
  datasource:
    username: ***
    url: jdbc:mysql://127.0.0.1:3306/advertisement?useSSL=false&autoReconnect=true
    password: ***
    tomcat:
      max-active: 4 #maximum connection
      min-idle: 2 #Minimum number of idle connections
      initial-size: 2 #Default number of initialized connections
eureka:
  client:
    service-url:
      defaultZone: http://server1:7777/eureka/,http://server2:8888/eureka/,http://server3:9999/eureka/
Create entity objects

Entity classes and database tables are generally one-to-one correspondences, commonly referred to as entity. Take user tables for example: Lombok portal

/**
 * AdUser for Entity class corresponding to database ad_user table
 * {@link Basic} The field information labeled as a database is labeled {@link Transient} if a field is needed that does not belong to the database.
 *
 * @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 //If not, the default is @Basic, which means a field in a database table.
      //@ Transient // If marked with the @Transient annotation, the current field is not a field in the table
    @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;

    /**
     * Required fields for creating users
     *
     * @param user_name 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 Universal State Enumeration
 *
 * @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang</a>
 */
@Getter
public enum CommonStatus {
    VALID(1, "effective"),
    INVALID(0, "invalid state");

    private Integer status;
    private String desc;

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

Other database corresponding entity classes (AdUnit, AdPlan, AdCreative, AdUnit District, AdUnit Hobby, AdUnit Keyword, Relationship Creative Unit), you can refer to the above examples to achieve their own, you can also go to github Download source code. ---

Be a good person.

Blog Garden | segmentfault | spring4all | csdn | Nuggets | OSChina | Brief book | Headlines | Know about | 51CTO

Posted by dave914 on Tue, 30 Jul 2019 20:29:49 -0700