Spring MVC +jdbctemplate returns multiple table queries list<bean>

Source: Internet
Author: User

Spring JDBC provides a beanpropertyrowmapper implementation that automatically maps the fields that are read in a database table to the properties of a domain object

Be resolute with JdbcTemplate Ah, the next method
first injected into the DAO.
@Autowired
Public jdbctemplate JdbcTemplate;

and then in the Springappplication.xml configuration.
<!--JDBC Injection --
<bean id= "JdbcTemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" >
<property name= "DataSource" >
<ref bean= "DataSource"/>
</property>
</bean>

then build a bean that fits your business

then write the DAO method

Java code

Public list<goodslistbean> findgoodslistbean (String goodsnum, integer vmid,           integer omid, string rusjstart,  string rusjend)  throws exception {      // if   (Userid == null)  {      // return new  Arraylist<pusmenu> ();      // }       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<goodslistbean> list = jdbctemplate.query (Sbstr.toString (),  new beanpropertyrowmapper (Goodslistbean.class));      return  list;  }



Finally, I'll just throw this list right into Easyui's rows.

Java code

List<goodslistbean> listg=new arraylist<goodslistbean> ();           //list<goodslistbean> listgend=new arraylist<goodslistbean > ();          try {               listg=goodsdao.findgoodslistbean (Goodsnum, vmid,  omid,rusjstart, rusjend);           } catch   (EXCEPTION&NBSP;E1)  {               // TODO Auto-generated catch block               e1.printstacktrace ();               logger.error ("Cargo query Exception", &NBSP;E1);               listg=new arraylist<goodslistbean> ();           }          mapjson.put (                    "Rows",    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LISTG);


Spring MVC +jdbctemplate returns multiple table queries list<bean>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.