Module: Mybatis::PoBuilder

Included in:
Builder
Defined in:
lib/mybatis/builder/po_builder.rb

Instance Method Summary collapse

Instance Method Details

#build_po(workspace, context) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mybatis/builder/po_builder.rb', line 5

def build_po(workspace,context)
  #实体类存放目录
  entity_path = get_po_folder workspace,context
  FileUtils.makedirs entity_path unless File.directory? entity_path

  file_path = "#{entity_path}#{context.po_name}.java"
  #实体类对应文件
  file = File.new file_path ,"w"
  file.puts "package #{context.package};" if context.package
  file.puts
  file.puts "/**"
  file.puts " * Created by mybatis-cli"
  file.puts " */"
  file.puts "public class #{context.po_name} {"

  context.attributes.each_with_index do |attr|
    file.puts "    private String #{attr.field_name};"
    file.puts
  end

  context.attributes.each_with_index do |attr|
    file.puts "    public String get#{attr.field_name.upcase_first}() {"
    file.puts "        return this.#{attr.field_name};"
    file.puts "    }"
    file.puts
  end
  context.attributes.each_with_index do |attr|
    file.puts "    public void set#{attr.field_name.upcase_first}(String #{attr.field_name}) {"
    file.puts "        this.#{attr.field_name} = #{attr.field_name};"
    file.puts "    }"
    file.puts
  end
  file.puts "}"
  file.close

  puts "create file: #{file_path}"
end