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