Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

spring mvc

//	https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html
Comment

Java Spring MVC

@RestController
@RequestMapping("/users")
public class MyRestController {

    private final UserRepository userRepository;

    private final CustomerRepository customerRepository;

    public MyRestController(UserRepository userRepository, CustomerRepository customerRepository) {
        this.userRepository = userRepository;
        this.customerRepository = customerRepository;
    }

    @GetMapping("/{userId}")
    public User getUser(@PathVariable Long userId) {
        return this.userRepository.findById(userId).get();
    }

    @GetMapping("/{userId}/customers")
    public List<Customer> getUserCustomers(@PathVariable Long userId) {
        return this.userRepository.findById(userId).map(this.customerRepository::findByUser).get();
    }

    @DeleteMapping("/{userId}")
    public void deleteUser(@PathVariable Long userId) {
        this.userRepository.deleteById(userId);
    }

}
Comment

spring mvc

Reference:
https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mvc.html
Comment

PREVIOUS NEXT
Code Example
Java :: POST method) in spring rest api 
Java :: try catch block 
Java :: runtime exception in java 
Java :: why we use return method 
Java :: How to remove an element from a Java List? 
Java :: method overloading 
Java :: java map sorted by key 
Java :: java programming problems 
Java :: nested class in java 8 
Java :: |= java operation 
Java :: lopping rows rethinkdb 
Java :: javafx combobox cell 
Java :: create fragment constructor in arrayadapter 
Java :: how to choose an element in a array list Java 
Java :: two dimensional arraylist in java 
Java :: show menuitem when menu hovered javafx 
Java :: map indexof java 
Java :: access db in fragments 
Java :: How to define lambda expression in Java? 
Java :: how to hide search from menu android studio from activity 
Java :: primitive vs wrapper classes in java 
Java :: sysout is not working in eclipse 
Java :: How do I retrieve editors registered for a certain file extension in Eclipse? 
Java :: Java Boolean Literals 
Java :: Java Labeled continue Statement Java 
Java :: conexion a mysql java 
Java :: java stream anymatch vs findany 
Java :: java datasource 
Java :: sort array from certain index java 
Java :: tipo map que permite armazenar na mesma chave java 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =