packagecom.mybatis.mapper;importjava.util.List;importorg.apache.ibatis.annotations.Delete;importorg.apache.ibatis.annotations.Insert;importorg.apache.ibatis.annotations.Select;importorg.apache.ibatis.annotations.Update;importcom.mybatis.pojo.Flower;/**
* 数据访问层
* @author Lenovo
*com.mybatis.mapper.FlowerMapper
*/publicinterfaceFlowerMapper{//增加@Insert("INSERT INTO flower(`name`,price,production) VALUES(#{name},#{price},#{production});")voidinsertInfo(Flower ff);//删除@Delete("DELETE FROM flower WHERE id=#{id}")voiddeleteInfo(int id);//修改@Update("UPDATE flower SET `name`=#{name},price=#{price},production=#{production} WHERE id=#{id}")voidupdateInfo(Flower ff);//查询@Select("SELECT * FROM flower;")List<Flower>selectAll();}
/**
* 查询;
* FlowerMapper fm = session.getMapper(FlowerMapper.class);
* FlowerMapper fm = new FlowerMapper();
*/@TestpublicvoidselectAll(){SqlSession session =this.getConnDB();//拿到FlowerMapper类/接口的完整名称FlowerMapper fm = session.getMapper(FlowerMapper.class);List<Flower> list = fm.selectAll();for(Flower flower : list){System.out.println(flower);}
session.close();}