feat(user): add user entity and repository with JPA integration
This commit is contained in:
@@ -9,7 +9,6 @@ dependencies {
|
||||
// Spring Boot Web(示例)
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
|
||||
|
||||
// Test
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.hanserwei.web;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan({"com.hanserwei.*"})
|
||||
@SpringBootApplication(scanBasePackages = "com.hanserwei")
|
||||
@EnableJpaRepositories(basePackages = "com.hanserwei.common.domain.repository")
|
||||
@EntityScan(basePackages = "com.hanserwei.common.domain.dataobject")
|
||||
public class WeblogWebApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WeblogWebApplication.class, args);
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.hanserwei.web;
|
||||
|
||||
import com.hanserwei.common.domain.dataobject.User;
|
||||
import com.hanserwei.common.domain.repository.UserRepository;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
class WeblogWebApplicationTests {
|
||||
|
||||
@Resource
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
@@ -23,4 +29,15 @@ class WeblogWebApplicationTests {
|
||||
log.info("这是一行带有占位符日志,作者:{}", author);
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
void insertTest() {
|
||||
User user = User.builder()
|
||||
.username("Hanserwei")
|
||||
.password("123456")
|
||||
.build();
|
||||
|
||||
// 使用jpa插入数据
|
||||
User savedUser = userRepository.save(user); // 保存并获取返回的实体
|
||||
userRepository.flush(); // 强制同步到数据库
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user