标签:android style blog http io color ar os sp
步骤1、新建的java工程,起名daoGenerator
步骤2:导入两个jar包,分别是freemarker-2.3.20.jar和greendao-generator-1.3.1.jar,下载路径:http://search.maven.org,你可以在这里搜索上述两个包,自己导入到java工程中,
导入的时候记着不要有中文路径
步骤3:新建daoGenerator.java文件,文件格式如下
import de.greenrobot.daogenerator.DaoGenerator; import de.greenrobot.daogenerator.Entity; import de.greenrobot.daogenerator.Property; import de.greenrobot.daogenerator.Schema; import de.greenrobot.daogenerator.ToMany; public class daoGenerator { public static void main(String[] args) throws Exception { Schema schema = new Schema(1,"com.example.menu"); addMenuDetail(schema); addMenuTable(schema); new DaoGenerator().generateAll(schema, "./"); } private static void addMenuTable(Schema schema) { Entity menuTable = schema.addEntity("MenuTable"); menuTable.addStringProperty("menuName");//菜单的名称(周一早餐通用版) menuTable.addIntProperty("menuType");//0早餐 1午餐 2晚餐 menuTable.addLongProperty("menuId").primaryKey().autoincrement();//菜单id menuTable.addStringProperty("menuCreateTime");//菜单创建时间 menuTable.addLongProperty("storeId");//店铺的编号 } private static void addMenuDetail(Schema schema) { Entity menuDetail = schema.addEntity("MenuDetail"); menuDetail.addStringProperty("menuDateId"); menuDetail.addLongProperty("menuId");//菜单id menuDetail.addIntProperty("widgetId");//控件id menuDetail.addStringProperty("type");//控件类型:textview、pic、line、verticalLine、theme、tips menuDetail.addStringProperty("name");//控件内容 "疙瘩汤" menuDetail.addDoubleProperty("x");//x menuDetail.addDoubleProperty("y");//y } }
该工程运行完毕会在当前目录下产生一个文件夹com,进入example再进入到menu(为什么会产生这样一个文件夹,这是由我们在程序中 Schema schema = new Schema(1,"com.example.menu"), new DaoGenerator().generateAll(schema, "./");这两行决定的,如果你运行出错,请查看你是不是路径写错),可以发现生成如下几个文件:
简要说明:menuDetail和menuTable就是我们在daoGenerator中指定生成的表,在生成的文件中每张表分别对应两个文件,举例:表menuTable对应的两个文件一个是menuTable,一个是menuTableDao。
menuTable.java文件主要是menuDetail中取得和设置列中元素的方法,见下图,注意:这是自动生成的代码,如果要修改列中元素名称可以在daoGenerator中修改:
1 package com.ShanFuBao.SmartCall.menu; 2 3 // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. 4 /** 5 * Entity mapped to table MENU_TABLE. 6 */ 7 public class MenuTable { 8 9 private String menuName; 10 private Integer menuType; 11 private Long menuId; 12 private String menuCreateTime; 13 private Long storeId; 14 15 public MenuTable() { 16 } 17 18 public MenuTable(Long menuId) { 19 this.menuId = menuId; 20 } 21 22 public MenuTable(String menuName, Integer menuType, Long menuId, String menuCreateTime, Long storeId) { 23 this.menuName = menuName; 24 this.menuType = menuType; 25 this.menuId = menuId; 26 this.menuCreateTime = menuCreateTime; 27 this.storeId = storeId; 28 } 29 30 public String getMenuName() { 31 return menuName; 32 } 33 34 public void setMenuName(String menuName) { 35 this.menuName = menuName; 36 } 37 38 public Integer getMenuType() { 39 return menuType; 40 } 41 42 public void setMenuType(Integer menuType) { 43 this.menuType = menuType; 44 } 45 46 public Long getMenuId() { 47 return menuId; 48 } 49 50 public void setMenuId(Long menuId) { 51 this.menuId = menuId; 52 } 53 54 public String getMenuCreateTime() { 55 return menuCreateTime; 56 } 57 58 public void setMenuCreateTime(String menuCreateTime) { 59 this.menuCreateTime = menuCreateTime; 60 } 61 62 public Long getStoreId() { 63 return storeId; 64 } 65 66 public void setStoreId(Long storeId) { 67 this.storeId = storeId; 68 } 69 70 }
标签:android style blog http io color ar os sp
原文地址:http://www.cnblogs.com/kunyashaw/p/4099310.html