grails-ibatis-plugin questions.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
tcl
Reply | Threaded
Open this post in threaded view
|

grails-ibatis-plugin questions.

tcl

I use the grails-ibatis-plugin and I finds some questions.

1:create grails plugin project: bookDomainPlugin

1>create domain class :com.example.Book.groovy as follow
  class Book{
  int id
        String bname
        static mapping = {
                table 'book'
                version false
                id column:'id',generator:'identity'
        }
  }
2> install grails-ibatis-1.2.1.zip
3>create-gateway com.example.Book
  then

  BookGateway.groovy
  book.xml
  <mapper namespace="com.example.book">
        <select id="getBook" parameterType="int" resultMap ="bookResultMap">
                select id,bname from book where id = #{id}
        </select>
       
        <resultMap id="bookResultMap" type="com.example.Book">
                <result column="id" property="id" />
                <result column="bname" property="bname" />
        </resultMap>
  </mapper>
4> create controller: grails create-controller com.example.Book
   BookController.groovy
   def index = {
        def bookGateway = new BookGateway()
        bookGateway.metaClass.methods.each{
                println it
        }
        def book = bookGateway.getBook(1)
        render "$book.bname"
   }
5>run the bookDomainPlugin: grails run-app,and try the: http://localhost:8080/bookDomainPlugin/book/index
  it is ok! I can find the "getBook" method.

Then
   
2.create grails project :bookManage
1>add the follow code to the "BuildConfig.groovy"
  grails.plugin.location.bookDomainPlugin="../bookDomainPlugin"
2>create controller: grails create-controller com.example.BookTest
  BookTestController.groovy
  def index={
        def bookGateway = new BookGateway()
        bookGateway.metaClass.methods.each{
                println it
        }
        def book = bookGateway.getBook(1)
        render "$book.bname"
  }
  It does not work!!!! It can not find the "getBook" method in the "bookGateway". who can you tell me why? Thank you very much!!!