You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.4 KiB
62 lines
1.4 KiB
package cc.bnblogs.springdatajpa.mapper; |
|
|
|
import cc.bnblogs.springdatajpa.pojo.User; |
|
import org.junit.jupiter.api.Test; |
|
import org.springframework.beans.factory.annotation.Autowired; |
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
/** |
|
* @description: |
|
* @author: zfp@bnblogs.cc |
|
* @date: 2023/3/7 15:30 |
|
*/ |
|
@SpringBootTest |
|
class UserMapperTest { |
|
@Autowired |
|
private UserMapper userMapper; |
|
@Test |
|
void save() { |
|
User user = new User(null,"lyl",20,"xxx@qq.com","1111"); |
|
userMapper.save(user); |
|
} |
|
|
|
@Test |
|
void select() { |
|
// userMapper.findAll().forEach(System.out::println); |
|
// System.out.println("userMapper.getUsers(1) = " + userMapper.getUserById(1)); |
|
// System.out.println(userMapper.updateNameById(1,"aaab")); |
|
} |
|
|
|
@Test |
|
void getDataByID(){ |
|
Optional<User> user = userMapper.findById(16); |
|
user.ifPresent(System.out::println); |
|
} |
|
|
|
@Test |
|
void updateDataByID(){ |
|
Optional<User> user = userMapper.findById(16); |
|
user.ifPresent(u -> { |
|
u.setName("admin"); |
|
User user0 = userMapper.save(u); |
|
System.out.println(user0); |
|
}); |
|
} |
|
|
|
@Test |
|
void deleteByID() { |
|
userMapper.deleteById(16); |
|
System.out.println(userMapper.findById(16).isPresent()); |
|
} |
|
|
|
@Test |
|
void getInfo() { |
|
userMapper.getAllName().forEach(System.out::println); |
|
} |
|
|
|
|
|
|
|
} |