我为Grails实现了Java域类,仅在此处的文档中进行了描述:http://docs.grails.org/latest/guide/hibernate.html

package foo.bar;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;



@Entity
public class A {

     @Id
     @GeneratedValue
     private Long id;

     @ElementCollection
     private List<String> buz;


     public Long getId() {
        return id;
     }

    public void setId(Long id) {
        this.id = id;
    }


     public void setBuz(List<String> buz) {
         this.buz = buz;
     }

     public List<String> getBuz() {
         return buz;
     }
}

和业务代码抛出异常:
def list = A.findAll()
list.each {
    if (it.buz.contains("foobar")) {
        result = it
}

it.buz-引发异常:Grails消息:



当我调用A.getBuz()直接捕获异常时:



无法理解,为什么Grails搜索静态方法getBuz()?
为什么按属性调用不起作用?

最佳答案

您输入了错字:

 public List<String> getBuz() {
     returb buz;
 }

应该是return buz;

10-05 18:35