我想初始化三个属性(companyTypes,carrierLists,和cabinLevels)为全局变量:
@Controller
@RequestMapping("/backend/basic")
public class TicketRuleController {
@Autowired
private CarrierService carrierService;
@Autowired
private CabinLevelService cabinLevelService;
@Autowired
private CompanyTypeService companyTypeService;
private List<DTOCompanyType> companyTypes = companyTypeService.loadAllCompanyTypes();
private List<DTOCarrier> carrierLists = carrierService.loadAllCarriers();
private List<DTOCabinLevel> cabinLevels = cabinLevelService.loadAllCabinLevel();
...
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
@Entity
@Table(name="dt_user" , uniqueConstraints = {@UniqueConstraint(columnNames="user_no"), @UniqueConstraint(columnNames="account")}
)
public class User implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -8149578944942492965L;
// Fields
private long id;
private String userNo;
private Set<UserRelative> userRelatives = new HashSet<UserRelative>(0);
// Constructors
/** default constructor */
public User() {
}
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="user")
public Set<UserRelative> getUserRelatives() {
return this.userRelatives;
}
}
Run Code Online (Sandbox Code Playgroud)
上面是用户实体;下面是另一个UserRelative实体:当想要getUserRelatives()时,问题就出现了.
@Entity
@Table(name="dt_user_relative")
public class UserRelative implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 5035928604641787267L;
// Fields …Run Code Online (Sandbox Code Playgroud)