时间:2022-10-05 11:22:22 | 栏目:JAVA代码 | 点击:次
实体对象如下:
/** 使用lobmok插件 */ @Getter @Setter @NoArgsConstructor @ToString @EqualsAndHashCode public class Vendor { private String vend_id; private String vend_name; private String vend_address; private String vend_city; private String vend_state; private String vend_zip; private String vend_country; }
XML映射文件如下:
<select id="findVendorAll" resultType="vendor"> select * from Vendors </select>
接口文件方法如下:
//查询所有记录 List<Vendor> findVendorAll();
测试文件如下:
try { String resource = "mybatis-config.xml"; InputStream resourceAsStream = Resources.getResourceAsStream(resource); SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream,"development2"); //获取SQLSession SqlSession openSession = build.openSession(); VendorMapper mapper = openSession.getMapper(VendorMapper.class); List<Vendors> findVendorAll = mapper.findVendorAll(); System.out.println(findVendorAll); } catch (IOException e) { System.out.println("加载配置文件失败"); e.printStackTrace(); }
笔记: