spring4-beanpropertyrowmapper-Querying multiple lines

Source: Internet
Author: User

1. Create project, project name (SPRINGDEMO9),

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/8F/07/wKioL1jR6z3wB833AAAUNakZBvQ997.png-wh_500x0-wm_ 3-wmp_4-s_2319270677.png "title=" Qq20170322111007.png "alt=" Wkiol1jr6z3wb833aaaunakzbvq997.png-wh_50 "/>


2. Create a directory in the project (src-> source directory,test-> Test Catalog,source-> configuration file directory, Lib->jar package directory),

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/8F/07/wKioL1jR68eSJ-24AAAvWT15Muk102.png-wh_500x0-wm_ 3-wmp_4-s_2800373096.png "title=" Qq20170322111222.png "alt=" Wkiol1jr68esj-24aaavwt15muk102.png-wh_50 "/>


3. Create the corresponding Jar package directory in Lib, which is used to distinguish jar packages.

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/8F/0A/wKiom1jR7BKy-TxDAAA7DP8WJ04182.png-wh_500x0-wm_ 3-wmp_4-s_4175925504.png "title=" Qq20170322111339.png "alt=" Wkiom1jr7bky-txdaaa7dp8wj04182.png-wh_50 "/>


4. Add the jar package in the corresponding Jar package directory of LIB.

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/8F/07/wKioL1jR7DzDS1nwAACWobN4Fbg057.png-wh_500x0-wm_ 3-wmp_4-s_1763101889.png "title=" Qq20170322111421.png "alt=" Wkiol1jr7dzds1nwaacwobn4fbg057.png-wh_50 "/>


5. Create entity Bean Forum, package name (Com.mycompany.shequ.bean) in the SRC directory,

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8F/0A/wKiom1jR7IrSEA0oAABEexYL1zc310.png-wh_500x0-wm_ 3-wmp_4-s_3990977426.png "title=" Qq20170322111539.png "alt=" Wkiom1jr7irsea0oaabeexyl1zc310.png-wh_50 "/>


6. Entity Bean Forum content is as follows
Package Com.mycompany.shequ.bean;public class Forum {private int fid;private String name;public int Getfid () {return FID;} public void Setfid (int fid) {this.fid = FID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;}}


7. Create interface Forumdao in src directory, package name (Com.mycompany.shequ.dao)

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/8F/07/wKioL1jR7ObQj56uAABHb-tg6rU097.png-wh_500x0-wm_ 3-wmp_4-s_2205997805.png "title=" Qq20170322111709.png "alt=" Wkiol1jr7obqj56uaabhb-tg6ru097.png-wh_50 "/>


8. Interface the contents of Forumdao are as follows

Package Com.mycompany.shequ.dao;import Java.util.list;import Com.mycompany.shequ.bean.forum;public interface Forumdao {public list<forum> findAll ();}


9.Create in src directoryForumdaothe implementation classForumdaoimpl, package name (Com.mycompany.shequ.dao.impl),

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/8F/0A/wKiom1jR7T_Du4n6AABDwtn1-80075.png-wh_500x0-wm_ 3-wmp_4-s_418912478.png "title=" Qq20170322111840.png "alt=" Wkiom1jr7t_du4n6aabdwtn1-80075.png-wh_50 "/>


10. forumdao forumdaoimpl are as follows

Package com.mycompany.shequ.dao.impl;import java.util.arraylist;import java.util.list;import  java.util.Map;import org.springframework.jdbc.core.BeanPropertyRowMapper;import  org.springframework.jdbc.core.support.jdbcdaosupport;import com.mycompany.shequ.bean.forum;import  com.mycompany.shequ.dao.forumdao;public class forumdaoimpl extends jdbcdaosupport  implements forumdao {@Overridepublic  list<forum> findall ()  {string sql  =  "Select * from hnsq_forum"; List<forum> forumlist = new arraylist<forum> ();forumList =  Getjdbctemplate (). Query (Sql, new beanpropertyrowmapper (Forum.class)); return forumlist;}}


11. Create the configuration file Spring-datasource.xml in the source directory,

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/8F/07/wKioL1jR7YHylyAZAAA4WDg4O4o384.png-wh_500x0-wm_ 3-wmp_4-s_1087069446.png "title=" Qq20170322111946.png "alt=" Wkiol1jr7yhylyazaaa4wdg4o4o384.png-wh_50 "/>


The contents of the configuration file Spring-datasource.xml are as follows

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xsi:schemalocation=" http://www.springframework.org/schema/beanshttp:// Www.springframework.org/schema/beans/spring-beans-3.0.xsd "><bean id=" DataSource "class=" Org.springframework.jdbc.datasource.DriverManagerDataSource "><property name=" Driverclassname "  Value= "com.mysql.jdbc.Driver"  /><property name= "url"  value= "jdbc:mysql://localhost:3306/b _shequ_two " /><property name=" username " value=" root " /><property name=" Password " value=" "&NBSP;/></BEAN></BEANS> 


13. Create the configuration file Applicationcontext.xml in the source directory,

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/8F/0A/wKiom1jR7bngPvlIAAA5emP2VMk682.png-wh_500x0-wm_ 3-wmp_4-s_3344843817.png "title=" Qq20170322112042.png "alt=" Wkiom1jr7bngpvliaaa5emp2vmk682.png-wh_50 "/>


14. Configuration Files Applicationcontext.xml the contents are as follows

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xsi:schemalocation=" http://www.springframework.org/schema/beanshttp:// Www.springframework.org/schema/beans/spring-beans-2.5.xsd "><import resource=" Spring-datasource.xml "/> <bean id= "Forumdao" class= "Com.mycompany.shequ.dao.impl.ForumDaoImpl" ><property name= "DataSource" ref= " DataSource "/></bean></beans>


15. Create the Forumdaoimpltest test class, Package name (COM.MYCOMPANY.SHEQU.DAO.IMPL) in the test directory,

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/8F/07/wKioL1jR7fbCzm9vAAA7HQbVZZk910.png-wh_500x0-wm_ 3-wmp_4-s_247838379.png "title=" Qq20170322112143.png "alt=" Wkiol1jr7fbczm9vaaa7hqbvzzk910.png-wh_50 "/>


The contents of the 16.ForumDaoImplTest test class are as follows

package com.mycompany.shequ.dao.impl;import java.util.list;import org.junit.test;import  org.springframework.context.applicationcontext;import  org.springframework.context.support.classpathxmlapplicationcontext;import com.mycompany.shequ.bean.forum; import com.mycompany.shequ.dao.forumdao;public class forumdaoimpltest {@Testpublic   Void testfindall () {    applicationcontext context = new  Classpathxmlapplicationcontext ("Applicationcontext.xml");         forumdao forumdao =  (Forumdao)  context.getbean ("Forumdao");     list <forum> forumlist = forumdao.findall ();         for (forum forum : forumlist) {    system.out.println (Forum.getFid ()  +   "_____"  + forum.getname ());     }}}


17. Run the Testfindall method in the test class and run the result

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/8F/07/wKioL1jR7lDT5JXIAAE-7rgz5as272.png-wh_500x0-wm_ 3-wmp_4-s_3332353230.png "title=" Qq20170322112311.png "alt=" Wkiol1jr7ldt5jxiaae-7rgz5as272.png-wh_50 "/>

This article is from the "Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1909147

spring4-beanpropertyrowmapper-Querying multiple lines

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.