-
Notifications
You must be signed in to change notification settings - Fork 0
3.执行静态sql
FuriousPws002 edited this page Apr 8, 2024
·
1 revision
执行简单无参保存方法,user表ddl如下
CREATE TABLE `user` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`age` int DEFAULT NULL,
`brith` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
执行序列图如下
单元测试:
public class SqlSessionTest {
@Test
public void staticSqlExecution() {
Configuration configuration = new Configuration();
configuration.setDataSource(DataSourceBuilderTest.build());
configuration.addMapper(UserMapper.class);
SqlSession sqlSession = new DefaultSqlSession(configuration);
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
userMapper.insert();
}
}
其中DataSourceBuilderTest类中密码设置为自己本地MySQL密码