Springboot application with RestFul endpoints having JPA one-to-many and many-to-one demo using H2
This project demonstrates One-To-Many and Many-To-One relation between two entities using spring boot and Spring Data JPA.
- SpringBoot
- Spring STS/Eclipse/Intellij
- Clean/Build in the IDE
- Run as SpringBoot App
- http://localhost:8080/weather should be up and running
- Additional data can be populated in the SpringBootCtsWeatherApplication file.
- /weather would fetch weather result for all the states and cities under it
endpoint : http://localhost:8080/weather/
[
{
"id": 1,
"state": "NJ",
"cities": [
{
"city": "Jersey City",
"temperature": "45",
"feels": "46"
},
{
"city": "Edison",
"temperature": "51",
"feels": "53"
}
]
},
{
"id": 2,
"state": "NY",
"cities": [
{
"city": "Downtown",
"temperature": "60",
"feels": "63"
},
{
"city": "Brooklyn",
"temperature": "71",
"feels": "80"
}
]
}
]
- /weather/ would fetch weather result for a state given its id
endpoint : http://localhost:8080/weather/1
{
"id": 1,
"state": "NJ",
"cities": [
{
"city": "Jersey City",
"temperature": "45",
"feels": "46"
},
{
"city": "Edison",
"temperature": "51",
"feels": "53"
}
]
}
- /weather/state/ would fetch for a particular state.
endpoint : http://localhost:8080/weather/state/NJ
{
"id": 1,
"state": "NJ",
"cities": [
{
"city": "Jersey City",
"temperature": "45",
"feels": "46"
},
{
"city": "Edison",
"temperature": "51",
"feels": "53"
}
]
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.