Code Monkey home page Code Monkey logo

spring-jdbc-ext's Introduction

Spring NamedParameterJdbcTemplate 扩展实现

为什么要使用`PageNamedParameterJdbcTemplate`

  • 简单 (命名参数, 类型自动封装)

  • 快速 (运行效率无限接近原生 jdbc)


比如我们向数据库插入(insert)一条数据

Person p = new Person();
p.setName("kevin");
p.setAddress("Shanghai");
p.setCountry("China");

namedTemplate.update(
  "insert into t_person(name, address, country) values(:name,:address,:country)",
  new BeanPropertySqlParameterSource(p))

查询`Person`数据

List<Person> persons = namedTemplate.query(
  "select * from person",
  EmptySqlParameterSource.INSTANCE,
  BeanPropertyRowMapper.newInstance(Person.class));

分页数据查询

int offset = 10, limit = 5;
PageHelper.set(offset, limit);  // 设置分页参数

String sql = "SELECT * FROM person";
PageResult<Person> pageResult = (PageResult) namedTemplate.query(
  "SELECT * FROM person",
  EmptySqlParameterSource.INSTANCE,
  BeanPropertyRowMapper.newInstance(Person.class));

long total = pageResult.getTotal(); // 总记录数
List<Person> persons = pageResult.getRows(); // 对应页码的行记录列表

spring-jdbc-ext's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.