是这样的,这是我做的第二个模块,刚创建好实体、表、和action—-service——dao三层,在页面想做个列表显示,却奇怪的发现不发sql,气得我忙了3个小时也查不出来,救命啊,大神们 前台的代码我就不贴出来了,请求的ACTION能到action层,就是到service时,debug跟踪为null,自己写测试类能测试成功 private IDepartmentService service; public void setService(IDepartmentService service) { this.service = service; } //分页查询的list public String list(){ System.out.println("进入"); List<Department> list = service.getAll(); Map<String,Object> map = new HashMap<>(); map.put("total", list.size()); map.put("rows", list); putAjaxData(map); return AJAX; } service代码: public interface IDepartmentService extends IBaseService<Department> { } IBaseService代码: public interface IBaseService<T> { public void save(T obj); public void update(T obj); public List<T> getAll(); public void delete(Long id); public T get(Long id); } BaseServiceImple代码: @Override public List<T> getAll() { return dao.getAll(entityClass); } BaseDaoImpl代码: @Override public List <T>getAll(Class entityClass) { return this.getHibernateTemplate().loadAll(entityClass); } Department.hbm.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="cn.itcast.domain.Department" table="t_department"> <id name="id"> <generator class="native"></generator> </id> <property name="departmentname" length="50" unique="true"></property> <property name="departmentmanager" length="50"></property> <property name="departmentdirector" length="50"></property> <property name="parentdepartment" length="50"></property> <!-- 描述部门的1对多 --> </class> </hibernate-mapping> |
|
40分 |
service为Null 那说明你注入有问题啊,如果用了spring 注入,看看你注入的哪里,顺便IDepartmentService?上面加个@Autowired,然后看看action里面 IDepartmentService?加个get方法试试
|