Spring JdbcTemplate Query

Source: Internet
Author: User

1. Spring JdbcTemplate query needs to implement the Maprow method

 PackageCom.cdv.apolloagent.jdbc.dao.impl;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.util.ArrayList;Importjava.util.List;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.jdbc.core.JdbcTemplate;ImportOrg.springframework.jdbc.core.RowMapper;Importorg.springframework.stereotype.Repository;ImportCom.cdv.apolloagent.jdbc.dao.TaskDao;ImportCom.cdv.apolloagent.model.Task; @Repository Public classTaskdaoimplImplementsTaskdao {@AutowiredPrivateJdbcTemplate JdbcTemplate; @Override PublicList<task> Findtasklist (intFlagintLimitintmax) {String SQL= "Select t.* from Task t where T.flag =?" Limit?,? "; List<Object> params =NewArraylist<object>();        Params.add (flag);        Params.add (limit);                Params.add (max); Object[] Para= Params.toarray (Newobject[params.size ()]); List<Task> taskList = This. Jdbctemplate.query (sql.tostring (), para,NewRowmapper<task>() {                     PublicTask Maprow (ResultSet RS,intRowNum)throwsSQLException {Task Task=NewTask (); Task.setid (Rs.getlong ("id")); Task.setworkorderid (Rs.getint ("Workorderid")); Task.setflag (Rs.getint ("Flag")); returntask;        }                }); returntaskList; }}

Spring JdbcTemplate Query

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.