NutzCN Logo
灌水 dao无法注入不能注入啊
发布于 2704天前 作者 qq_82c21724 2444 次浏览 复制 上一个帖子 下一个帖子
标签:

@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class, args={"*js", "ioc/",
// 这个package下所有带@IocBean注解的类,都会登记上
"*anno", "com.util",
"*tx", // 事务拦截 aop
"*async"})

@Ok("json:full")
@Fail("jsp:jsp.500")
@Localization(value="msg/", defaultLocalizationKey="zh-CN")
@Views({JetTemplateViewMaker.class})
@Modules(scanPackage=true)
public class MainModule {

}

--------------------------------------------------------------------------------
public abstract class BaseModule {
/** 注入同名的一个ioc对象 */
@Inject protected Dao dao;


@IocBean
public class UserModule extends BaseModule{

@Inject
protected userService userService;
@At
public int count(){
    return dao.count(User.class);
}
@At
public Object query(@Param("name")String name){
     Cnd cnd = Strings.isBlank(name)? null : Cnd.where("name", "like", "%"+name+"%");
     User user = new User();
     user = (User) dao.query(User.class, cnd);
     return user; 
}

 protected User checkUser(User user) {
     user.setId(user.getId());
     user.setName(user.getName());
     user.setDate(user.getDate());
     user.setHf(user.getHf());
     user.setCj(user.getCj());
     user.setAddname(user.getAddname());
     user.setDeletename(user.getDeletename());
     return user;
 }

 @At
 public Object add(@Param("..")User user) { // 两个点号是按对象属性一一设置
        NutMap re = new NutMap();
       /* String msg = checkUser(user);
        System.out.println(msg.getName()+"===============");*/
        System.out.println("+++++"+dao);
        dao.insert(user);

        if (user != null){
            return re.setv("ok", false).setv("user", user);
        }

// user = userService.add(user.getId(),user.getName(),user.getDate(),user.getHf(),user.getCj(),
// user.getAddname(),user.getDeletename());
return re.setv("ok", true).setv("data", user);
}


var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["custom/"]
}
},
dataSource : {
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
},
fields : {
url : {java:"$conf.get('db.url')"},
username : {java:"$conf.get('db.username')"},
password : {java:"$conf.get('db.password')"},
testWhileIdle : true,
validationQuery : {java:"$conf.get('db.validationQuery')"},
maxActive : {java:"$conf.get('db.maxActive')"},
filters : "mergeStat",
connectionProperties : "druid.stat.slowSqlMillis=2000"

        }
    },
    dao : {
        type : "org.nutz.dao.impl.NutDao",
        args : [{refer:"dataSource"}]
    },
    myModule : {
        type : 'com.you.app.MyModule',
        scope : 'request',
        fields : {
            request : {refer: '$request'}
        }
    }

};

0 回复
添加回复
该帖子已被锁定,不能回复.
回到顶部