Spring JDBC提供了一个BeanPropertyRowMapper的实现,能够自动将数据库表中读出的字段与Domain对象的属性进行映射
果断用 jdbctemplate啊 下面 说下方法
首先 在dao里 注入下
@Autowired
public JdbcTemplate jdbcTemplate;
然后在springappplication.xml里 配置下
然后建立一个符合自己业务的bean
然后写dao方法
public ListfindGoodsListBean(String goodsnum, Integer vmid, Integer omid, String rusjstart, String rusjend) throws Exception { // if (userid == null) { // return new ArrayList (); // } StringBuilder sbstr = new StringBuilder( "SELECT g.*,u.name acceptancename,c.name companyname,vm.name vmname" + " ,om.name omname,cc.name contactsname FROM goods g,pus_sys_user u,companyinfors c " + " ,variety_management vm,origin_management om ,companycontacts cc WHERE g.acceptanceid=u.id" + " AND g.companyid=c.id AND g.vmid=vm.id AND g.omid=om.id " + " AND g.contactsid=cc.id AND g.state=1"); List list = jdbcTemplate.query(sbstr.toString(), new BeanPropertyRowMapper(GoodsListBean.class)); return list; }
最后把这个list直接丢到easyui的rows里就好了
Listlistg=new ArrayList (); //List listgend=new ArrayList (); try { listg=goodsDao.findGoodsListBean(goodsnum, vmid, omid,rusjstart, rusjend); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); logger.error("货物查询异常", e1); listg=new ArrayList (); } mapjson.put( "rows", listg);