Spring jdbctemplate query, using Beanpropertyrowmapper

Source: Internet
Author: User

Application:

Use spring's jdbctemplate to query the database, get a list of lists of results, database table fields and entity classes automatically correspond, you can use beanpropertyrowmapper.

Note: The Beanpropertyrowmapper implements the RowMapper interface.

Attention:

Automatic binding requires the same column name as the Java entity class name, such as: The property name "UserName" can match the column field "UserName" or "user_name" in the database. In this way, we do not need a manual binding, greatly improving the development efficiency.

Query code:

@Override
Public list<userentity> finduser (userentity user) {
Logger.info ("query statement:" + sel_by_username_pwd);

List<userentity> userlist = Jdbctemplate.query (Sel_by_username_pwd,
New object[] {user.getusername (), User.getpwd ()},
New Beanpropertyrowmapper<userentity> (Userentity.class));
return userlist;
}

Sql:

Private static final String sel_by_username_pwd = "SELECT * from" + Constantlist.t_shuju_admin_user + "A S sp WHERE sp.username =? and sp.pwd =? ";

Spring jdbctemplate query, using Beanpropertyrowmapper

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.