表如下:
工程结构:
其中admin,user表的访问没有问题。dao访问不了数据库中的其他表.贴出最简单的Kind,求助,我不知道是不是配置问题,第一次用Nutz
package com.my.nutz.pojo;
import java.io.Serializable;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;
@Table("kind")
public class Kind implements Serializable{
private static final long serialVersionUID = 1L;
@Id
private Integer kid;
@Column
private String kname;
//省略geter & seter
}
就是查不出结果,也不报错。。。。
package com.my.nutz.service;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
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.Ok;
import org.nutz.mvc.annotation.Param;
import com.my.nutz.pojo.Kind;
@IocBean
@At("/kind")
public class KindService {
@Inject
protected Dao dao;
//-------------------------------Query----------------------------
@At
@Ok("beetl:jsp/kind.html")
public void doQuery(@Param("kname")String name,HttpSession session,HttpServletRequest request){
if(name==null) name="";
Cnd cnd = Cnd.where("name", "like", "%"+name+"%");
List<Kind> kinds = dao.query(Kind.class,cnd);
request.setAttribute("kinds", kinds);
}
}
dao.js
var ioc = {
dataSource : {
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
},
fields : {
url : "jdbc:mysql://127.0.0.1:3306/nutz",
username : "root",
password : "123",
testWhileIdle : true,
validationQuery : "select 1" ,
maxActive : 100
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"dataSource"}]
}
};
MainModule
package com.my.nutz;
import org.beetl.ext.nutz.BeetlViewMaker;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.annotation.Views;
import org.nutz.mvc.ioc.provider.ComboIocProvider;
@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class, args={"*js", "ioc/",
"*anno", "com.my.nutz",
"*tx"})
@Modules(scanPackage=true)
@Views(BeetlViewMaker.class)
public class MainModule {
}
MainSetup
package com.my.nutz;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;
import com.my.nutz.pojo.Admin;
public class MainSetup implements Setup {
public void init(NutConfig conf) {
Ioc ioc = conf.getIoc();
Dao dao = ioc.get(Dao.class);
Daos.createTablesInPackage(dao, "com.my.nutz", false);
if (dao.count(Admin.class) == 0) {
Admin admin = new Admin();
admin.setUname("admin");
admin.setPassword("123456");
dao.insert(admin);
}
}
public void destroy(NutConfig conf) {
}
}