1、配置数据库映射文件(User.xml)
在其中加入如下代码:
<!--
添加用户
parameterType:指定输入的参数类型是pojo
#{}中指定pojo的属性名,接收到pojo对象的属性值,mybatis也是通过OGNL来获取对象的属性值
-->
<insert id="insertUser" parameterType="pojo.User">
INSERT INTO USER VALUES(#{id},#{username},#{birthday},#{sex},#{address});
</insert>
注意:在此处的parameterType中,指定的是对象名,而不是简单数据类型,在下方指定pojo的各属性名
2、编写程序
//添加用户
@Test
public void insertUser(){
//mybatis配置文件
String resource = "SqlMapConfig.xml";
SqlSession sqlSession = null;
try {
InputStream inputStream = Resources.getResourceAsStream(reso