小编xuy*_*ing的帖子

如何通过Spring在Controller中添加构造函数

我想初始化三个属性(companyTypescarrierLists,和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)

我怎样才能做到这一点?

java spring

1
推荐指数
1
解决办法
4302
查看次数

没有懒惰地初始化一个角色集合

@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)

spring dao hibernate

1
推荐指数
1
解决办法
4019
查看次数

标签 统计

spring ×2

dao ×1

hibernate ×1

java ×1