NutzCN Logo
问答 大神求解 为什么缺少构造方法
发布于 2827天前 作者 qq_6175ecf9 2249 次浏览 复制 上一个帖子 下一个帖子
标签:

dao.js的内容:
/**
* 链接数据库
*/
var ioc={
dataSource:{
type:"com.alibaba.druid.pool.DruidDataSource",
events:{
create:"init",
depose:"close"
}
,
fields:{
url:"jdbc:mysql://localhost:3306/nutzbook?useUnicode=true&characterEncoding=UTF-8",
username:"root",
password:"root",
initialSize:5,
minIdle:1,
maxActive:100,
timeBetweenEvictionRunsMillis:3000,
minEvictableIdleTimeMillis:300000,
poolPreparedStatements:"true",
maxPoolPreparedStatementPerConnectionSize:20,
maxWait:60000,
filters:"mergeStat"
}
},
dao:{
type : "org.nutz.dao.impl.NutDao",
args : [ {
refer : "dataSource"
} ]
},
employeeService:{
type : "demo.nutz.service.EmployeeService",
args : [ {
refer : "dao"
} ]
}
}
EmployeeService接口的內容:
package demo.nutz.service;

import java.util.Map;

import org.nutz.ioc.loader.annotation.IocBean;

import demo.nutz.model.EmployeeModel;
@IocBean(args={"refer:dao"})
public interface EmployeeService {

/** 
 * 添加 
 * @param model 
 */  
 public Map<String, Object> save(EmployeeModel model); 
/** 
 * 删除 
 * @param ids 
 */  
public Map<String, Object> delete(String ids);  
/** 
 * 加载 
 */  
public Map<String, Object> init(int rows,int page);
public EmployeeModel fetch(int id);  

}
EmployeeServiceImpl實現類的代碼:
package demo.nutz.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.dao.pager.Pager;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.service.IdEntityService;

import demo.nutz.model.DutyModel;
import demo.nutz.model.EmployeeModel;
@IocBean(args = {"refer:dao"})
public class EmployeeServiceImpl extends IdEntityService implements EmployeeService {

public EmployeeServiceImpl(Dao dao) {
    super(dao);
}
/**
 * 添加人员信息
 */
  public Map<String, Object> save(EmployeeModel model) {  
        Map<String, Object> result = new HashMap<String, Object>();  
        try {  
            EmployeeModel query = this.dao().fetch(EmployeeModel.class, model.getId());  
            if(null!=query){  
                this.dao().update(model);  
            }else{  
                this.dao().insert(model);  
            }  
            result.put("type", "0");  
            result.put("message", "保存成功");  
        } catch (RuntimeException e) {  
            result.put("type", "1");  
            result.put("message", e.getMessage());  
            e.printStackTrace();  
        }  
        return result;  
    }
/**
 * 删除人员信息
 */
@Override
public Map<String, Object> delete(String ids) {
    Map<String, Object> result = new HashMap<String, Object>();  
    try {  
        this.dao().clear(EmployeeModel.class, Cnd.where("id", "in", ids));  
        result.put("type", "0");  
        result.put("message", "删除成功");  
    } catch (RuntimeException e) {  
        result.put("type", "1");  
        result.put("message", e.getMessage());  
        e.printStackTrace();  
    }  
    return result;
}

/**
 * 查询所有人员信息  分页进行
 */
@Override
public Map<String, Object> init(int rows, int page) {
    // TODO Auto-generated method stub
     Map<String, Object> result = new HashMap<String, Object>();  
        Pager pager = new Pager();  
        pager.setPageNumber(page);  
        pager.setPageSize(rows);  
        List<EmployeeModel> list = this.dao().query(EmployeeModel.class, null,pager);  
        for(EmployeeModel model : list){  
           // this.dao().fetchLinks(model, "duty"); 
            this.dao().fetchLinks(model, "duty");
            DutyModel duty = model.getDuty();  
            if(null!=duty){  
                model.setViewDuty(duty.getName());  
            }  
        }  
        result.put("total", this.dao().query(EmployeeModel.class, null).size());  
        result.put("rows", list);  
        return result;  
}
@Override
public EmployeeModel fetch(int id) {
    return this.fetch(id);
}

}
主模塊的代碼:
package demo.nutz.ModuleMain;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import demo.nutz.model.EmployeeModel;
import demo.nutz.service.EmployeeService;
import demo.nutz.service.EmployeeServiceImpl;

@IocBy(args={"*js", "ioc/",
// 这个package下所有带@IocBean注解的类,都会登记上
"*anno", "demo.nutz",
"*tx", // 事务拦截 aop
"*async"}) // 异步执行aop
@IocBean
public class EmployeeModule {
@Inject
private EmployeeService employeeService;
@At("/employee/save")
@Ok("json")
public Map<String, Object> save(@Param("model") EmployeeModel model) {
return this.employeeService.save(model);
}

/**
* 加载
* denghui
*/
@At("/employee/init")
@Ok("json")
// 返回形式是jsp
public Map<String, Object> init(HttpServletRequest request,int rows,int page) {
System.out.println("zzzzzzzz");
Map<String, Object> map = this.employeeService.init(rows,page);
return map;
}

/**
* 编辑
* @param request
*/
@At("/employee/edit")
@Ok("jsp:/sys_employee_edit.jsp")
// 返回形式是jsp
public void edit(HttpServletRequest request, int id) {
EmployeeModel model = this.employeeService.fetch(id);
request.setAttribute("model", model);
}
}
为什么说Fail to born 'demo.nutz.service.EmployeeService' @(org.nutz.dao.impl.NutDao@22bb4fb5)] because: No suitable Constructor or Factory Method!!
at org.nutz.lang.Mirror.getBorning(Mirror.java:954)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:107)
... 33 more
请大神指教

6 回复

type定义错了,应该用EmployeeServiceImpl。

@IocBean(name="employeeService",args = {"refer:dao"})

不行啊 我修改了一下@IocBean(name="employeeService",args = {"refer:dao"})

EmployeeServiceImpl 上的@IocBean

 @Inject
 private EmployeeService employeeService;

老版本需要把对应的bean声明为一样的名称, 所以

@IocBean(name="employeeService",args = {"refer:dao"})
public class EmployeeServiceImpl extends IdEntityService implements EmployeeService {
添加回复
请先登陆
回到顶部