insert into t_car(id,car_num,brand,guide_price,produce_time,car_type)
values (null,#{k1},#{k2},null,null,null)
其中k1,k2为map集合中的值
SqlSession sqlSession= SqlSessionUtil.openSession();
Car car=new Car(null,"3333","比亚迪秦",null,null,null);
int count=sqlSession.insert("insertCar",car);
System.out.println(count);
sqlSession.commit();
sqlSession.close();
insert into t_car(id,car_num,brand,guide_price,produce_time,car_type)
values (null,#{carNum},#{brand},#{guidePrice},#{produceTime},#{carType})
利用pojo类传参,#{}中写的是get方法中的方法名去掉get,然后将剩下的单词首字母小写,然后放进去
<select id="selectById" resultType="com.powernode.mybatis.pojo.Car">
select * from t_car where id= #{id}
</select>
查询时需要指定resultType类型 找到类,copy reference复制路径,这里注意数据库查询的列名和类的变量名保持一致
xml中的namespace用来指定命名空间,防止重复。写法为namespace.id
可以不编写接口的实现类生成实现类的对象
必须在xml中的namespace中指定mapper接口的全路径
将id填写为相应的方法名
需要获取接口的代理对象
xxxx mapper=sqlSession.getMapper(xxxx.class);
mapper.xxxxxxx()调用相应的方法