标签:
最近开发的一个项目主要有两个特点,这两点也是在项目开发前需要着重去规划解决方案的:
compile ‘com.github.satyan:sugar:1.3‘
<applicationandroid:label="@string/app_name"android:icon="@drawable/icon" android:name="com.orm.SugarApp"> . . <meta-dataandroid:name="DATABASE"android:value="sugar_example.db"/> <meta-dataandroid:name="VERSION"android:value="2"/> <meta-dataandroid:name="QUERY_LOG"android:value="true"/> <meta-dataandroid:name="DOMAIN_PACKAGE_NAME"android:value="com.example.bean"/> . . </application>
public class Goods extends SugarRecord implements Serializable { /** * 货品编号 */ @Column(name = "sku_ID", unique = true) @Expose private String skuId; /** * 商品编号 */ @Expose private String spuId; /** * 规格 */ @Expose @Ignore private String specValue; /** * 货品名称 */ @Expose private String name; /** * 货号 */ @Expose private String bn; /** * 成本价,进价 */ @Expose private BigDecimal cost; /** * 售价 */ @Expose private BigDecimal price; public String getSkuId() { return skuId; } public void setSkuId(String skuId) { this.skuId = skuId; } public String getSpuId() { return spuId; } public void setSpuId(String spuId) { this.spuId = spuId; } public String getSpecValue() { return specValue; } public void setSpecValue(String specValue) { this.specValue = specValue; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getBn() { return bn; } public void setBn(String bn) { this.bn = bn; } public BigDecimal getCost() { return cost; } public void setCost(BigDecimal cost) { this.cost = cost; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } }
Goods good = new Goods(); good.setName("Coffee"); good.setCost(new BigDecimal(30)); good.setBn("123456"); good.save();
Goods loadGood =Goods.findById(Goods.class,1);
List<Goods> goods =Goods.listAll(Goods.class);
:
Goods good2 = Goods.findById(Goods.class, 1); good2.setName("Rice"); good2.save();
Goods good2 = Goods.findById(Goods.class, 1); good2.delete();
Goods.deleteAll(Goods.class);
Goods.find(Goods.class, "name = ? and skuId = ?", "Coffee", "123");
find(Class<T> type, String whereClause, String[] whereArgs, String groupBy, String orderBy, String limit)
List<Note> notes = Note.findWithQuery(Note.class, "Select * from Note where name = ?", "satya");
Select.from(TestRecord.class) .where(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2)) .list();
public class Operator extends SugarRecord implements Serializable { String userName; String gender; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } }
:
public class Goods extends SugarRecord implements Serializable { ... private Operator operator; public Operator getOperator() { return operator; } public void setOperator(Operator operator) { this.operator = operator; } ... }
List<Goods> goods = Goods.find(Goods.class, "operator = ?", new String{operator.getName()});
Goods good = Goods.findById(Goods.class, 1); Operator o = good.getOperator();
用SugarORM快速开发需要同步和保存大量数据的Android互联网客户端
标签:
原文地址:http://www.cnblogs.com/soaringEveryday/p/4825286.html