自做代码生成器(三)动手写代码_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 自做代码生成器(三)动手写代码

自做代码生成器(三)动手写代码

 2011/10/18 6:10:45  bd2007  http://bd2007.iteye.com  我要评论(0)
  • 摘要:定义好规则和配置格式,就可以开始动手写代码了,首先,需要两个class来保存表的信息和字段信息,还需要从表的xml文件中提取出表的信息,代码如下:field.java<divclass='codeareajava'><divstyle='color:#000000;'><br/><fontcolor='#0000ff'>package</font><fontcolor='#000000'>com</font>
  • 标签:代码 写代码
    ??? 定义好规则和配置格式,就可以开始动手写代码了,首先,需要两个class来保存表的信息和字段信息,还需要从表的xml文件中提取出表的信息,代码如下:
field.java
<div class='codearea java'><div style='color: #000000;'><br/><font color='#0000ff'>package</font>?<font color='#000000'>com</font><font color='#000000'>.</font><font color='#000000'>bang</font><font color='#000000'>.</font><font color='#000000'>dev</font><font color='#000000'>.</font><font color='#000000'>autocoder</font><font color='#000000'>;</font> <br/><br/><font color='#0000ff'>public</font>?<font color='#0000ff'>class</font>?<font color='#ff0000'>field</font>?<font color='#000000'>{</font><br/>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldlabel</font><font color='#000000'>;</font>??<font color='#006600'>//字段标签<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldcomment</font><font color='#000000'>;</font>?<font color='#006600'>//注释<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldname</font><font color='#000000'>;</font>??<font color='#006600'>//字段名<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldclassname</font><font color='#000000'>;</font>?<font color='#006600'>//转换以后的java类名<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldtype</font><font color='#000000'>;</font>??<font color='#006600'>//字段类型<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldclasstype</font><font color='#000000'>;</font>?<font color='#006600'>//转换以后的java类型<br/></font>????<font color='#0000ff'>private</font>?<font color='#0000ff'>int</font>?<font color='#000000'>fieldlen</font><font color='#000000'>;</font>???<font color='#006600'>//字段长度??<br/></font>????<font color='#0000ff'>private</font>?<font color='#0000ff'>int</font>?<font color='#000000'>fieldnull</font><font color='#000000'>;</font>???<font color='#006600'>//字段空标志<br/></font>????<font color='#0000ff'>private</font>?<font color='#0000ff'>boolean</font>?<font color='#000000'>readonly</font><font color='#000000'>;</font>??<font color='#006600'>//只读标志<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldformtype</font><font color='#000000'>;</font>?<font color='#006600'>//保留,表单类型<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>fieldseq</font><font color='#000000'>;</font>??<font color='#006600'>//序列<br/></font>????<font color='#0000ff'>private</font>?<font color='#ff0000'>string</font>?<font color='#000000'>defaultvalue</font><font color='#000000'>;</font>?<font color='#006600'>//默认值 <br/></font><br/>?<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getdefaultvalue</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>return</font>?<font color='#000000'>defaultvalue</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/>?<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setdefaultvalue</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>defaultvalue</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>defaultvalue</font>?<font color='#000000'>=</font>?<font color='#000000'>defaultvalue</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldtype</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldtype</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldtype</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldtype</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldname</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldname</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldname</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldname</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldlen</font><font color='#000000'>(</font><font color='#0000ff'>int</font>?<font color='#000000'>fieldlen</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldlen</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldlen</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldnull</font><font color='#000000'>(</font><font color='#0000ff'>int</font>?<font color='#000000'>fieldnull</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldnull</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldnull</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setreadonly</font><font color='#000000'>(</font><font color='#0000ff'>boolean</font>?<font color='#000000'>readonly</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>readonly</font>?<font color='#000000'>=</font>?<font color='#000000'>readonly</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>int</font>?<font color='#000000'>getfieldlen</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldlen</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldname</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldname</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldtype</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldtype</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>int</font>?<font color='#000000'>getfieldnull</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldnull</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>boolean</font>?<font color='#000000'>isreadonly</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>readonly</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>?<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldclassname</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>return</font>?<font color='#000000'>fieldclassname</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/>?<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldclassname</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldclassname</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldclassname</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldclassname</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/>?<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldclasstype</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>return</font>?<font color='#000000'>fieldclasstype</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldlabel</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldlabel</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldformtype</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldformtype</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldseq</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>return</font>?<font color='#000000'>fieldseq</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldclasstype</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldclasstype</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldclasstype</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldclasstype</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldlabel</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldlabel</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldlabel</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldlabel</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldformtype</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldformtype</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldformtype</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldformtype</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>????<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldseq</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldseq</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>????????<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldseq</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldseq</font><font color='#000000'>;</font><br/>????<font color='#000000'>}</font> <br/><br/>?<font color='#0000ff'>public</font>?<font color='#ff0000'>string</font>?<font color='#000000'>getfieldcomment</font><font color='#000000'>()</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>return</font>?<font color='#000000'>fieldcomment</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font> <br/><br/>?<font color='#0000ff'>public</font>?<font color='#0000ff'>void</font>?<font color='#000000'>setfieldcomment</font><font color='#000000'>(</font><font color='#ff0000'>string</font>?<font color='#000000'>fieldcomment</font><font color='#000000'>)</font>?<font color='#000000'>{</font><br/>??<font color='#0000ff'>this</font><font color='#000000'>.</font><font color='#000000'>fieldcomment</font>?<font color='#000000'>=</font>?<font color='#000000'>fieldcomment</font><font color='#000000'>;</font><br/>?<font color='#000000'>}</font><br/><font color='#000000'>}</font><br/>
发表评论
用户名: 匿名