MyBatis第一天

MyBatis第一天

  1. 导入jar包
    MyBatis第一天_第1张图片
    2.编写实体类
package com.demo.pojo;
/**
 * 实体类
 * @author Administrator
 *
 */
public class Flower {
	private int id;
	private String name;
	private double price;
	private String production;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public String getProduction() {
		return production;
	}
	public void setProduction(String production) {
		this.production = production;
	}
	@Override
	public String toString() {
		return "Flower [id=" + id + ", name=" + name + ", price=" + price + ", production=" + production + "]";
	}
	
}

3.配置mybatis.xml




	
		
			
			
			
			
				
				
				
				
			
		
	
	
		
	

4.配置FlowerMapper.xml




	实体类名字区分大小写
	

5.编写测试类

	@Test
	public void selAll() throws IOException{
		InputStream is = Resources.getResourceAsStream("mybatis.xml");
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
		SqlSession session = factory.openSession();
		List list = session.selectList("a.b.selAll");
		for (Flower flower : list) {
			System.out.println(flower.toString());
		}
		session.close();
	}

你可能感兴趣的:(mybatis)