Skip to main content

Posts

Showing posts with the label Rest Api

How to Implement One to Many and Many to One Mapping in Spring Boot using JPA

Spring Boot CRUD example using One-to-Many and Many to One mapping | With Thymeleaf User Interface In this tutorial, we will learn how to use @OneToMany and @ManyToOne annotation using JPA (Java Persistent API) in Spring Boot. We also attach Thymeleaf for User Interface. In past tutorial, we already created Spring Boot CRUD with Rest API, JPA and MySql. Please refer that one first, we will continue from there. Spring Boot application with Thymeleaf, Rest API, JPA and MySql Database    For applying One to Many relationship, we need another POJO class. In past we already created Book class, now we will create new class Author . As we know Author have multiple Books, so we can easily apply One to Many operation. Lets create POJO class for Author and apply @OneToMany on Book .  Define List of Book and apply @OneToMany annotation on field. We are using mappedBy property, so Author table does not create new column.  We already learn about mappedBy property in One-to-One a...

Spring Boot Crud Operation with Thymeleaf, JPA and MySql Database | Step by Step

Spring Boot application with Thymeleaf, Rest API, JPA and MySql Database In this article, we will seen how to create simple Spring boot application with Create, Read, Update and Delete operations with MySql and Thymeleaf. But first checkout what is Thymeleaf? Thymeleaf :- Thymeleaf is modern server side Java template engine for web and standalone environment. Thymeleaf's main goal is to bring elegant natural templates to your development workflow — HTML that can be correctly displayed in browsers and also work as static prototypes, allowing for stronger collaboration in development teams. So lets start our Tutorial :- First learn how to create Spring Boot application with Rest API, JPA and Mysql.  Spring Boot CRUD operation with Rest API, JPA and MySql   Project Structure :- For Create Spring Boot project and Sql table click on Above given link. 1. Configure Maven Dependency For work with Thymeleaf we have to include " spring-boot-starter-thymeleaf " Dependen...

How to convert JSONObject and JSONArray into Java List | JSONArray and JSONObject

Convert JSON Object data into Java List and Display accordingly | Convert String JSONObject and JSONArray data into List in Java Often times we need to call Third party API and we get JSON response, and want to display data into web page. Sometimes we got complex JSON response and difficult to convert into Java data structure. First learn how to call third party rest API in Java.   How to call 3rd party API in Java So lets see how we can easily convert JSON data into our Java data structure. Following sample JSON data. { "ProgrammingList": [ { "id": "1", "name": "Java", "edition": "third" }, { "id": "2", "name": "Python", "edition": "fourth" }, { "id": "3", "name": "JavaScript", "edition": "Fifth" }, { "id...

How to call 3rd party API in Java using HttpURLConnection | Get and Post Request

Implementing GET and POST Request for calling third party API in Java   As a developer, often times we need to call third party APIs for getting or saving data. We can simply call GET request for getting data and POST request for save data or if needed to send parameters in body section.  In this article, we seen how we can use GET and POST request for calling third party Rest APIs. In java, we can simply call third party API using HttpURLConnection class and get response accordingly.  We can use following methods in HttpURLConnection class. GET POST HEAD OPTIONS PUT DELETE TRACE So lets see how we can call third party API. i am using https://jsonplaceholder.typicode.com   to make GET and POST calls. This website provides free API endpoints. GET request : Get request simply returns data (response). GET request does not accepts any body section data. See sample of GET requests : https://example.com/data  https://example.com/data/1 Calling GET request is easy. Bec...