mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-04 15:54:52 +08:00 
			
		
		
		
	feat(mapper): 添加 MpUserMapper 及用户插入测试
新增 MpUserMapper 接口,扩展自 Mybatis Plus 的 BaseMapper,用于 User 实体的数据库操作。在 UserMapperTest 中添加 testAddUser 方法以验证用户插入功能,使用 SQLite 数据库进行单元测试。
This commit is contained in:
		
							parent
							
								
									e9bbc1e274
								
							
						
					
					
						commit
						a8f39e2b0c
					
				
							
								
								
									
										3
									
								
								.github/workflows/maven.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/workflows/maven.yml
									
									
									
									
										vendored
									
									
								
							@ -21,6 +21,7 @@ jobs:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
    - uses: actions/checkout@v4
 | 
					    - uses: actions/checkout@v4
 | 
				
			||||||
 | 
					    - run: rm -rf test.db
 | 
				
			||||||
    - name: Set up JDK 17
 | 
					    - name: Set up JDK 17
 | 
				
			||||||
      uses: actions/setup-java@v4
 | 
					      uses: actions/setup-java@v4
 | 
				
			||||||
      with:
 | 
					      with:
 | 
				
			||||||
@ -28,7 +29,7 @@ jobs:
 | 
				
			|||||||
        distribution: 'temurin'
 | 
					        distribution: 'temurin'
 | 
				
			||||||
        cache: maven
 | 
					        cache: maven
 | 
				
			||||||
    - name: Build with Maven
 | 
					    - name: Build with Maven
 | 
				
			||||||
      run: mvn -B package -DskipTests --file pom.xml
 | 
					      run: mvn -B package --file pom.xml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
 | 
					    # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
 | 
				
			||||||
#    - name: Update dependency graph
 | 
					#    - name: Update dependency graph
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -32,3 +32,4 @@ build/
 | 
				
			|||||||
### VS Code ###
 | 
					### VS Code ###
 | 
				
			||||||
.vscode/
 | 
					.vscode/
 | 
				
			||||||
/src/main/resources/application.yaml
 | 
					/src/main/resources/application.yaml
 | 
				
			||||||
 | 
					/test.db
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								pom.xml
									
									
									
									
									
								
							@ -95,6 +95,11 @@
 | 
				
			|||||||
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
 | 
					            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
 | 
				
			||||||
            <version>2.3.0</version>
 | 
					            <version>2.3.0</version>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
 | 
					        <dependency>
 | 
				
			||||||
 | 
					            <groupId>org.xerial</groupId>
 | 
				
			||||||
 | 
					            <artifactId>sqlite-jdbc</artifactId>
 | 
				
			||||||
 | 
					            <scope>test</scope>
 | 
				
			||||||
 | 
					        </dependency>
 | 
				
			||||||
    </dependencies>
 | 
					    </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <build>
 | 
					    <build>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,13 @@
 | 
				
			|||||||
package top.suyiiyii.sims;
 | 
					package top.suyiiyii.sims;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.tangzc.autotable.springboot.EnableAutoTable;
 | 
					import com.tangzc.autotable.springboot.EnableAutoTable;
 | 
				
			||||||
 | 
					import org.mybatis.spring.annotation.MapperScan;
 | 
				
			||||||
import org.springframework.boot.SpringApplication;
 | 
					import org.springframework.boot.SpringApplication;
 | 
				
			||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
					import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*@EnableAutoTable*/
 | 
					@EnableAutoTable
 | 
				
			||||||
@SpringBootApplication
 | 
					@SpringBootApplication
 | 
				
			||||||
 | 
					@MapperScan("top.suyiiyii.sims.mapper")
 | 
				
			||||||
public class SimsApplication {
 | 
					public class SimsApplication {
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
        SpringApplication.run(SimsApplication.class, args);
 | 
					        SpringApplication.run(SimsApplication.class, args);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										7
									
								
								src/main/java/top/suyiiyii/sims/mapper/MpUserMapper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main/java/top/suyiiyii/sims/mapper/MpUserMapper.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					package top.suyiiyii.sims.mapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.entity.User;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface MpUserMapper extends BaseMapper<User> {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								src/main/resources/application-test.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/main/resources/application-test.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					spring:
 | 
				
			||||||
 | 
					  datasource:
 | 
				
			||||||
 | 
					    url: jdbc:sqlite:test.db:testdb?cache=shared
 | 
				
			||||||
 | 
					    driver-class-name: org.sqlite.JDBC
 | 
				
			||||||
 | 
					    username:
 | 
				
			||||||
 | 
					    password:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										33
									
								
								src/test/java/top/suyiiyii/sims/mapper/UserMapperTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/test/java/top/suyiiyii/sims/mapper/UserMapperTest.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					package top.suyiiyii.sims.mapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.Assertions;
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
 | 
					import org.springframework.boot.test.context.SpringBootTest;
 | 
				
			||||||
 | 
					import org.springframework.test.context.ActiveProfiles;
 | 
				
			||||||
 | 
					import top.suyiiyii.sims.entity.User;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@SpringBootTest
 | 
				
			||||||
 | 
					@ActiveProfiles("test")
 | 
				
			||||||
 | 
					public class UserMapperTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private MpUserMapper userMapper;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void testAddUser() {
 | 
				
			||||||
 | 
					        User user = new User();
 | 
				
			||||||
 | 
					        user.setStudentId(1);
 | 
				
			||||||
 | 
					        user.setUsername("test");
 | 
				
			||||||
 | 
					        user.setPassword("test");
 | 
				
			||||||
 | 
					        user.setEmail("test");
 | 
				
			||||||
 | 
					        user.setGrade("test");
 | 
				
			||||||
 | 
					        user.setUserGroup("test");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        int result = userMapper.insert(user);
 | 
				
			||||||
 | 
					        Assertions.assertEquals(1, result);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user