先說定時執(zhí)行。
springboot的應用,要讓它定時調(diào)用一個方法,可以用 @Scheduled 注解。 注解是注解在方法上。
```
@Component
public class SomeClass {
? ? @Scheduled(cron="00? 30? 21? *? *? *")
? ? public void thisMethod() {
? ? ? ? ? // do something
? ? }
}
```
以上的意思就是每天的21:30:00 執(zhí)行 thisMethod() 這個方法。
當然,默認情況下,這個定時執(zhí)行是不開的,要讓他開,還需要在SpringBootApplication 上,增加一個 @EnableScheduling? 這個注解:
```
@SpringBootApplication
@EnableScheduling
public class TcflowApplication {
? ? public static void main(String[] args) {
? ? ? ? SpringApplication.run(TcflowApplication.class, args);
? ? }
}
```
再說 JPA的Id, id一般是可以通過生成器來生成的。咱mysql的auto_increment 如何搞呢,這么搞:
```
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="e_flow")
public class Flowimplements Serializable {
? ? @Id
? ? @GeneratedValue(strategy=GenerationType.IDENTITY)
? ? public Longid;
? ? @Column(name="day")
? ? public Stringday;
? ? @Column(name="innum")
? ? public IntegerinNum;
? ? @Column(name="outnum")
? ? public IntegeroutNum;
}
```
沒錯,就是用 GenerationType.IDENTITY