添加依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.9</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.24</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>com.rick.db</groupId>
<artifactId>sharp-database</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
数据库配置文件:
server:
port: 8080
spring:
datasource:
name: druidDataSource
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
username: root
password: root
initialSize: 1
minIdle: 5
maxActive: 10
maxWait: 60000
sharp:
database: # 多个包扫描用 , 隔开
entity-base-package: com.rick.sharp.**.entity
测试
@SpringBootApplication
@DependsOn("entityDAOSupport")
@EnableScheduling
public class DemoApplication {
@Autowired
private EntityDAO<User, Long> userDAO;
@Autowired
private EntityDAO<CodeDescription, Long> codeDescriptionDAO;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
String ss = JsonUtils.toJson("ss");
System.out.println(ss);
System.out.println("running.....");
}
@Scheduled(fixedRate = 5000)
public void find() {
User user = userDAO.selectById(1L).get();
System.out.println(user.getName());
codeDescriptionDAO.insert(CodeDescription.builder()
.code("test-" + System.currentTimeMillis())
.description("hello")
.category(CodeDescription.CategoryEnum.MATERIAL)
.build());
}
}