MangoProject实例

1、创建项目

2、添加jar包

mango-1.5.2.jar
mysql-connector-java-5.1.26-bin.jar

3、编写各程序

//Goods.java

public class Goods {
    private Integer id;
    private String name;
    private double price;
    private int count;

    public Integer getId() {
        return id;
    }
    public void setId(Integer 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 int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    //
    public Goods(Integer id, String name, double price, int count) {
        super();
        this.id = id;
        this.name = name;
        this.price = price;
        this.count = count;
    }  
}

 

//GoodsDao.java

public interface GoodsDao {
    //1 插入
    @SQL("insert into Goods(name,price,count) values(:1, :2, :3)")
    public void add(String name, Double price, int num);

    //2 查询
    @SQL("select sum(count) from Goods where name=:1")
    public int getTotalCount(String name);
    
    //3 删除
    @SQL("delete from Goods where ID=:1")
    public void delete(int id);    
    
}

//TestMango.java

public class TestMango {

    public static void main(String[] args) {
        String driverClassName = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3308/mangodb";
        String username = "root";
        String password = "root";  
        DataSource ds = new DriverManagerDataSource(driverClassName, url, username, password);
        Mango mango = Mango.newInstance(ds);
        GoodsDao dao = mango.create(GoodsDao.class);
        dao.add("OA", 19.0,200);
        System.out.println(dao.getTotalCount("OA"));
        dao.delete(7);
    }    
}

 

posted on 2017-08-10 17:03  daivsing  阅读(137)  评论(0)    收藏  举报