Module: Mybatis::MapperBuilder

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

Instance Method Summary collapse

Instance Method Details

#build_mapper(workspace, context) ⇒ Object



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
# File 'lib/mybatis/builder/mapper_builder.rb', line 6

def build_mapper(workspace,context)
  #实体类存放目录
  mapper_path = get_mapper_path workspace,context

  FileUtils.makedirs mapper_path unless File.directory? mapper_path

  file_path = "#{mapper_path}#{context.po_name}Mapper.java"
  #实体类对应文件
  file = File.new file_path ,"w"
  if context.mapper_package != ''
    file.puts "package #{context.mapper_package};"
  else
    file.puts "package #{context.package}.mapper;" if context.package
  end
  file.puts
  file.puts "import #{context.join_package_and_po_name};"
  file.puts
  file.puts "/**"
  file.puts " * Created by mybatis-cli"
  file.puts " */"
  file.puts "public interface #{context.po_name}Mapper {"
  file.puts "      void insert(#{context.po_name} #{context.po_name.downcase_first});"
  file.puts
  file.puts "      void delete(int id);"
  file.puts
  file.puts "      void update(#{context.po_name} #{context.po_name.downcase_first});"
  file.puts
  file.puts "      #{context.po_name} select(int id);"
  file.puts
  file.puts "}"
  file.close

  puts "create file: #{file_path}"
end