Code Monkey home page Code Monkey logo

aula-jparepository's Introduction

JpaRepository: interface boladona do Spring

DevSuperior - Nelio Alves

Image

Siga-nos:

https://instagram.com/devsuperior.ig

https://youtube.com/devsuperior

Trechos de código

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
INSERT INTO tb_users(name,email,salary) VALUES ('Maria','[email protected]',1348.74);
INSERT INTO tb_users(name,email,salary) VALUES ('Joao Silva','[email protected]',9276.62);
INSERT INTO tb_users(name,email,salary) VALUES ('Carlos Silva','[email protected]',7318.75);
INSERT INTO tb_users(name,email,salary) VALUES ('Adriana','[email protected]',10688.93);
INSERT INTO tb_users(name,email,salary) VALUES ('Karina','[email protected]',7251.28);
INSERT INTO tb_users(name,email,salary) VALUES ('Carlos Marques','[email protected]',5485.79);
INSERT INTO tb_users(name,email,salary) VALUES ('Carlos Pereira','[email protected]',3519.41);
INSERT INTO tb_users(name,email,salary) VALUES ('Ana Maria','[email protected]',2569.20);
INSERT INTO tb_users(name,email,salary) VALUES ('Beatriz','[email protected]',3853.33);
INSERT INTO tb_users(name,email,salary) VALUES ('Joana','[email protected]',4222.91);
INSERT INTO tb_users(name,email,salary) VALUES ('Tulio Augusto','[email protected]',9453.69);
INSERT INTO tb_users(name,email,salary) VALUES ('Augusto','[email protected]',4119.91);
INSERT INTO tb_users(name,email,salary) VALUES ('Marta','[email protected]',4519.15);
INSERT INTO tb_users(name,email,salary) VALUES ('Silvio','[email protected]',5285.68);
INSERT INTO tb_users(name,email,salary) VALUES ('Washington','[email protected]',6439.99);
INSERT INTO tb_users(name,email,salary) VALUES ('Teresa','[email protected]',8929.78);
INSERT INTO tb_users(name,email,salary) VALUES ('Luciano','[email protected]',3360.72);
INSERT INTO tb_users(name,email,salary) VALUES ('Fabiana','[email protected]',2532.83);
INSERT INTO tb_users(name,email,salary) VALUES ('Fabio','[email protected]',5912.88);
INSERT INTO tb_users(name,email,salary) VALUES ('Gisele','[email protected]',7558.26);
INSERT INTO tb_users(name,email,salary) VALUES ('Larissa','[email protected]',2362.04);
INSERT INTO tb_users(name,email,salary) VALUES ('Natanael','[email protected]',6860.63);
INSERT INTO tb_users(name,email,salary) VALUES ('Meire','[email protected]',3553.40);
INSERT INTO tb_users(name,email,salary) VALUES ('Ana Carolina','[email protected]',1404.28);
INSERT INTO tb_users(name,email,salary) VALUES ('Filipe','[email protected]',3388.73);
@Autowired
private UserRepository repository;

@GetMapping
public ResponseEntity<List<User>> findAll() {
    List<User> result = repository.findAll();
    return ResponseEntity.ok(result);
}

@GetMapping(value = "/page")
public ResponseEntity<Page<User>> findAll(Pageable pageable) {
    Page<User> result = repository.findAll(pageable);
    return ResponseEntity.ok(result);
}

@GetMapping(value = "/search-salary")
public ResponseEntity<Page<User>> searchBySalary(@RequestParam(defaultValue = "0") Double minSalary, @RequestParam(defaultValue = "1000000000000") Double maxSalary, Pageable pageable) {
    Page<User> result = repository.findBySalaryBetween(minSalary, maxSalary, pageable);
    return ResponseEntity.ok(result);
}

@GetMapping(value = "/search-name")
public ResponseEntity<Page<User>> searchByName(@RequestParam(defaultValue = "") String name, Pageable pageable) {
    Page<User> result = repository.findByNameContainingIgnoreCase(name, pageable);
    return ResponseEntity.ok(result);
}
@Query("SELECT obj FROM User obj WHERE obj.salary >= :minSalary AND obj.salary <= :maxSalary")
Page<User> searchBySalary(Double minSalary, Double maxSalary, Pageable pageable);

@Query("SELECT obj FROM User obj WHERE LOWER(obj.name) LIKE LOWER(CONCAT('%',:name,'%'))")
Page<User> searchByName(String name, Pageable pageable);

Page<User> findBySalaryBetween(Double minSalary, Double maxSalary, Pageable pageable);

Page<User> findByNameContainingIgnoreCase(String name, Pageable pageable);

aula-jparepository's People

Contributors

acenelio 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.