每天写的代码会有很多重复性工作,比如每个新功能的model、service、dao 类和接口的新建。
昨晚用python里Template写了一个自动生成的脚本,贴出代码分享。
import os
import sys
from string import Template
def produceModel(parameters):
modelClass(parameters)
defModelHBM(parameters)
def produceService(parameters):
serviceInter(parameters)
serviceImpl(parameters)
def produceDao(parameters):
daoInter(parameters)
daoImpl(parameters)
def modelClass(parameters):
code = Template('''package\n
public class ${className} {\n
${attribute}
${methods}
}
''')
name = parameters[0] # class name
argv2 = parameters[1]
attribute = ""
methods = ""
properties = argv2.split(",")
for x in range(len(properties)):
prop = properties[x].split(":")
propType = prop[1]
propName = prop[0]
attribute += "\tprivate " + propType + " " + propName + ";\n