在DAO中:
private Map<Integer,String> departments = new LinkedHashMap<Integer, String>();
@Override
public List<DepartmentEntity> getAllDepartments() {
return this.sessionFactory.getCurrentSession().createQuery("from DepartmentEntity de order by LOWER(de.departmentname)").list();
}
@Override
public Map<Integer, String> loadDepartments() {
departments.clear();
for (DepartmentEntity de : getAllDepartments())
departments.put(de.getDepartmentid(), de.getDepartmentname());
return departments;
}
它的工作正常,但在春季手动创建对象时,其错误代码
private Map<Integer,String> departments;
因此,在我的情况下,如何从外部注入LinkedHashMap类型的地图对象?
我试过但是我得到了像空指针异常这样的异常
请任何人帮助我..
最佳答案
<util:map id="myMap" map-class="java.util.LinkedHashMap" key-type="java.lang.Integer" value-type="java.lang.String"/>
<bean id="departmentDAOImpl" class="com.leadwinner.infra.assets.dao.DepartmentDAOImpl">
<property name="departments" ref="myMap"></property>
</bean>