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 :: java array 
Java :: java interview questions for freshers 
Java :: java unicode characters 
Java :: how to encrypt password in properties file in spring boot 
Java :: super class java 
Java :: keycloak spring boot application.properties 
Java :: spring mongodb 
Java :: pass data to layout from navigation android studio 
Java :: java to python 
Java :: How to send saved CSV file via email 
Java :: Method Overloading by changing the data type of parameters Java 
Java :: random class in java 
Java :: java regex of eauations 
Java :: get method jdbc 
Java :: java method overloading 
Java :: convert kotlin code to java 
Java :: Creategoogle maps marker with custom image/bitmap 
Java :: expression régulière seulement un espace java 
Java :: java fill in the code to read and store the next value in the array 
Java :: spigot bukkit self cancelling task timer example repeat times 
Java :: calculate tip and sales tax function 
Java :: java longest paldrome 
Java :: output of java file in terminal 
Java :: acceder a elementos de list java 
Java :: java 2d array previous object 
Java :: how to enforce xml dtd validation in java 
Java :: convert python to java translator online 
Java :: android on change class event 
Java :: final java 
Java :: how to assign one value to 2 variable in one line in java 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =