可以插入,读取表中内容 不能删除
@SpringBootTest
public class PetsitterTest {
@Autowired
public UserMapper userMapper;
@Test
public void select () {
List<user> list = userMapper.selectList(null);
for (Object object : list) {
System.out.println(object);
}
}
@Test
public void inster (){
//新增用户信息
//INSERT INTO user ( user_psw, user_id, user_name, user_img ) VALUES ( ?, ?, ?, ? )
user user = new user();
user.setUser_id(19);
user.setUser_name("nuibi");
user.setUser_psw("123456");
user.setUser_img("haokan");
int insert = userMapper.insert(user);
System.out.println("受影响的行数:" + insert);
System.out.println("id:"+user.getUser_id());
}
@Test
public void delete(){
List<Long> list = Arrays.asList(1L, 2L);
int i = userMapper.deleteById(19L);
//int i = userMapper.deleteBatchIds(list);
System.out.println("删除了:"+i);
}
}
不会报错
Warn: Could not find @TableId in Class: com.example.pojo.user.
2022-03-19 18:08:59.317 INFO 11708 --- [ main] com.example.PetsitterTest : Started PetsitterTest in 2.556 seconds (JVM running for 3.694)
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@ffd4cba] was not registered for synchronization because synchronization is not active
2022-03-19 18:08:59.574 INFO 11708 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-03-19 18:08:59.775 INFO 11708 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@2043889470 wrapping com.mysql.cj.jdbc.ConnectionImpl@4dad0eed] will not be managed by Spring
==> Preparing: DELETE FROM user WHERE null=?
==> Parameters: 1(Long)
<== Updates: 0
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@ffd4cba]
删除了:0
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@fd09e43] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@1510312933 wrapping com.mysql.cj.jdbc.ConnectionImpl@4dad0eed] will not be managed by Spring
==> Preparing: INSERT INTO user ( user_psw, user_id, user_name, user_img ) VALUES ( ?, ?, ?, ? )
==> Parameters: 123456(String), 101(Long), nuibi(String), haokan(String)
<== Updates: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@fd09e43]
受影响的行数:1
id:101
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@52ea0269] was not registered for synchronization because synchronization is not active
JDBC Connection [HikariProxyConnection@2062828451 wrapping com.mysql.cj.jdbc.ConnectionImpl@4dad0eed] will not be managed by Spring
==> Preparing: SELECT user_psw,user_id,user_name,user_img FROM user
==> Parameters:
<== Columns: user_psw, user_id, user_name, user_img
<== Row: 123456, 1, qhy, quh
<== Row: 123456, 2, qhy, quh
<== Row: 123456, 3, qhy, quh
<== Row: 123456, 5, nuibi, haokan
<== Row: 123456, 9, nuibi, haokan
<== Row: 123456, 10, nuibi, haokan
<== Row: 123456, 11, nuibi, haokan
<== Row: 123456, 14, nuibi, haokan
<== Row: 123456, 15, nuibi, haokan
<== Row: 123456, 19, nuibi, haokan
<== Row: 123456, 100, nuibi, haokan
<== Row: 123456, 101, nuibi, haokan
<== Total: 12
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@52ea0269]
user(user_id=1, user_img=quh, user_name=qhy, user_psw=123456)
user(user_id=2, user_img=quh, user_name=qhy, user_psw=123456)
user(user_id=3, user_img=quh, user_name=qhy, user_psw=123456)
user(user_id=5, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=9, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=10, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=11, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=14, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=15, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=19, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=100, user_img=haokan, user_name=nuibi, user_psw=123456)
user(user_id=101, user_img=haokan, user_name=nuibi, user_psw=123456)
解决不了 ~