{"id":82,"date":"2019-03-02T02:09:13","date_gmt":"2019-03-02T02:09:13","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?p=82"},"modified":"2019-03-02T04:08:01","modified_gmt":"2019-03-02T04:08:01","slug":"09-spring-boot-write-get-methods","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/","title":{"rendered":"Spring Boot &#8211; Write GET Methods"},"content":{"rendered":"<p>In this lesson, we are going to write the GET methods to get list of items. So we would write methods to return list of users. Then we would write method to return list of Posts. Finally, we write method to return list of Locations.<\/p>\n<p>We&#8217;ll cover the following:<\/p>\n<ol>\n<li><a href=\"#t1\">Write and Test a GET Method<\/a><\/li>\n<li><a href=\"#t2\">Write the Method to return List of Users<\/a><\/li>\n<li><a href=\"#t3\">Write the Method to return List of Posts<\/a><\/li>\n<li><a href=\"#t4\">Write the Method to return List of Locations<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"\">1. Write and Test a GET Method<\/strong><\/h4>\n<p>So we would first write a GET method. This method would just return a string &#8220;Welcome to Spring Boot&#8221; when the someone accesses \/welcome. To do this, create a new class and name it welcomeController.<\/p>\n<p>Inside this file write a function that write\u00a0 function welcome() that returns a string &#8220;Welcome to Spring Boot&#8221;<\/p>\n<p>Annotate the class with @RestConroller annotation<\/p>\n<p>Annotate the function with @RestMapping annotation<\/p>\n<p>If you have done everything right, the content of you welcomeController file would be as shown below.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> com<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">kindsonthegenius<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">social<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RequestMapping<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RestController<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@RestController<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">welcomeController<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n\t<span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"\/welcome\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">static<\/span> String <span style=\"color: #0066bb; font-weight: bold;\">welcome<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"background-color: #fff0f0;\">\"Welcome to Spring Boot\"<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.0: Content of the welcomeController.java<\/p>\n<p>&nbsp;<\/p>\n<p>Now you can start the application. Then open the browser and enter http:\/\/localhost:8080\/welcome<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"\">2. Write the Method to return List of Users<\/strong><\/h4>\n<p>Here we will write the function that would return list of all the users in our SocialAPI.<\/p>\n<p>Open the UserController file you created in the previous tutorial. Inside this file you will do the following things:<\/p>\n<p>create a function and name if getAllUsers()<\/p>\n<p>annotate this function with @RestMapping annotation<\/p>\n<p>inside this function create a hard-coded list of users<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> com<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">kindsonthegenius<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">social<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">user<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Arrays<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.List<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RequestMapping<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RestController<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">com.kindsonthegenius.social.location.Location<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@RestController<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">userController<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n   <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value<span style=\"color: #333333;\">=<\/span><span style=\"background-color: #fff0f0;\">\"\/users\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n   <span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>User<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAllUsers<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\tUser user1 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> User<span style=\"color: #333333;\">(<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"u1\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jany\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Lawrence\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">Location<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l1\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Lagos\"<\/span><span style=\"color: #333333;\">),<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jany@gmail.com\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\r\n\tUser user2 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> User<span style=\"color: #333333;\">(<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"u2\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jadon\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Mills\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">Location<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l2\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Asaba\"<\/span><span style=\"color: #333333;\">),<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jadon@gmail.com\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> Arrays<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">asList<\/span><span style=\"color: #333333;\">(<\/span>user1<span style=\"color: #333333;\">,<\/span> user2<span style=\"color: #333333;\">);<\/span>\t\r\n\t\r\n   <span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.1: Content of the userController.java file<\/p>\n<p>&nbsp;<\/p>\n<p>Now you can test the application.<\/p>\n<p>Right-click on the project and Run As SpringBoot Application. Then go to the broser and access http:\/\/localhost:8080\/users. You will get a list of users.<\/p>\n<p>If not let me know in the comment box below.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Write the Method to return List of Posts<\/strong><\/h4>\n<p>Here we will write the function that would return list of all the posts in our SocialAPI.<\/p>\n<p>Open the PostController file you created in the previous tutorial. Inside this file you will do the following things:<\/p>\n<p>create a function and name if getAllPosts()<\/p>\n<p>annotate this function with @RestMapping annotation. See the video<\/p>\n<p>inside this function create a hard-coded list of posts<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> com<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">kindsonthegenius<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">social<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">post<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Arrays<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.List<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RequestMapping<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RestController<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">com.kindsonthegenius.social.location.Location<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">com.kindsonthegenius.social.user.User<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@RestController<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">PostController<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n   <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/posts\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n   <span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Post<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAllPosts<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\r\n\tUser user1 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> User<span style=\"color: #333333;\">(<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"u1\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jany\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Lawrence\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">Location<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l1\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Lagos\"<\/span><span style=\"color: #333333;\">),<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jany@gmail.com\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\r\n\tUser user2 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> User<span style=\"color: #333333;\">(<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"u2\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jadon\"<\/span><span style=\"color: #333333;\">,<\/span> \r\n\t\t<span style=\"background-color: #fff0f0;\">\"Mills\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">new<\/span> <span style=\"color: #0066bb; font-weight: bold;\">Location<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l2\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Asaba\"<\/span><span style=\"color: #333333;\">),<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"Jadon@gmail.com\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\r\n\tPost post1 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Post<span style=\"color: #333333;\">(<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"p1\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"01-Jan-19\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\tuser1<span style=\"color: #333333;\">,<\/span>\r\n\t        <span style=\"background-color: #fff0f0;\">\"Its good to love and be loved\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\t\t\r\n\tPost post2 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Post<span style=\"color: #333333;\">(<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"p2\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t        <span style=\"background-color: #fff0f0;\">\"02-Jan-19\"<\/span><span style=\"color: #333333;\">,<\/span>\r\n\t\tuser2<span style=\"color: #333333;\">,<\/span>\r\n\t\t<span style=\"background-color: #fff0f0;\">\"We all need someone\"<\/span><span style=\"color: #333333;\">);<\/span>\t\t\r\n\t\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> Arrays<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">asList<\/span><span style=\"color: #333333;\">(<\/span>post1<span style=\"color: #333333;\">,<\/span> post2<span style=\"color: #333333;\">);<\/span>\r\n \r\n   <span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.2: Content of the postController.java file<\/p>\n<p>&nbsp;<\/p>\n<p>Now you can test the getAllPosts method.<\/p>\n<p>Right-click on the project and Run As SpringBoot Application. Then go to the browser and access http:\/\/localhost:8080\/posts. You will get a list of posts.<\/p>\n<p>If not let me know in the comment box below.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"\">4. Write the Method to return List of Locations<\/strong><\/h4>\n<p>Here we will write the function that would return list of all the posts in our SocialAPI. This would be easier than the previous two.<\/p>\n<p>Open the LocationController file you created in the previous tutorial. Inside this file you will do the following things:<\/p>\n<p>create a function and name if getAllLocations()<\/p>\n<p>annotate this function with @RestMapping annotation. See the video<\/p>\n<p>inside this function create a hard-coded list of locations<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.Arrays<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.List<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RequestMapping<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">org.springframework.web.bind.annotation.RestController<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@RestController<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">LocationController<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\r\n   <span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\/locations\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n   <span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Location<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAllLocations<\/span><span style=\"color: #333333;\">()<\/span> \r\n   <span style=\"color: #333333;\">{<\/span>\r\n\tLocation location1 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Location<span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l1\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Lagos\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\tLocation location2 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Location<span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l2\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Asaba\"<\/span><span style=\"color: #333333;\">);<\/span>\r\n\tLocation location3 <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> Location<span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"l3\"<\/span><span style=\"color: #333333;\">,<\/span> <span style=\"background-color: #fff0f0;\">\"Budapest\"<\/span><span style=\"color: #333333;\">);<\/span>\t\r\n\t\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> Arrays<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">asList<\/span><span style=\"color: #333333;\">(<\/span>location1<span style=\"color: #333333;\">,<\/span> location2<span style=\"color: #333333;\">,<\/span> location3<span style=\"color: #333333;\">);<\/span>\r\n   <span style=\"color: #333333;\">}<\/span>\t\t\r\n\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>Listing 1.3: Content of the LocationController.java file<\/p>\n<p>&nbsp;<\/p>\n<p>As usual, go ahead to test the getAllLocations method.<\/p>\n<p>If you completed this part successfully, then thumbs up to you! Next we would see how to write POST methods.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>In this lesson, we are going to write the GET methods to get list of items. So we would write methods to return list of &hellip; <!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":83,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Boot - Write GET Methods - Learn Spring Boot<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot - Write GET Methods - Learn Spring Boot\" \/>\n<meta property=\"og:description\" content=\"In this lesson, we are going to write the GET methods to get list of items. So we would write methods to return list of &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn Spring Boot\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-02T02:09:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-02T04:08:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Write-GET-Methods.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"781\" \/>\n\t<meta property=\"og:image:height\" content=\"451\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"headline\":\"Spring Boot &#8211; Write GET Methods\",\"datePublished\":\"2019-03-02T02:09:13+00:00\",\"dateModified\":\"2019-03-02T04:08:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/\"},\"wordCount\":554,\"commentCount\":23,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Write-GET-Methods.jpg\",\"articleSection\":[\"Spring Boot Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/\",\"name\":\"Spring Boot - Write GET Methods - Learn Spring Boot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Write-GET-Methods.jpg\",\"datePublished\":\"2019-03-02T02:09:13+00:00\",\"dateModified\":\"2019-03-02T04:08:01+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Write-GET-Methods.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2019\\\/03\\\/Write-GET-Methods.jpg\",\"width\":781,\"height\":451},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/09-spring-boot-write-get-methods\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot &#8211; Write GET Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/\",\"name\":\"Learn Spring Boot\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/#\\\/schema\\\/person\\\/7f8fc5792578d2ff54003fcebe6c46b5\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/spring-boot\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot - Write GET Methods - Learn Spring Boot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/","og_locale":"en_US","og_type":"article","og_title":"Spring Boot - Write GET Methods - Learn Spring Boot","og_description":"In this lesson, we are going to write the GET methods to get list of items. So we would write methods to return list of &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/","og_site_name":"Learn Spring Boot","article_published_time":"2019-03-02T02:09:13+00:00","article_modified_time":"2019-03-02T04:08:01+00:00","og_image":[{"width":781,"height":451,"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Write-GET-Methods.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"headline":"Spring Boot &#8211; Write GET Methods","datePublished":"2019-03-02T02:09:13+00:00","dateModified":"2019-03-02T04:08:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/"},"wordCount":554,"commentCount":23,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Write-GET-Methods.jpg","articleSection":["Spring Boot Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/","name":"Spring Boot - Write GET Methods - Learn Spring Boot","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Write-GET-Methods.jpg","datePublished":"2019-03-02T02:09:13+00:00","dateModified":"2019-03-02T04:08:01+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Write-GET-Methods.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-content\/uploads\/sites\/7\/2019\/03\/Write-GET-Methods.jpg","width":781,"height":451},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/09-spring-boot-write-get-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/spring-boot\/"},{"@type":"ListItem","position":2,"name":"Spring Boot &#8211; Write GET Methods"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#website","url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/","name":"Learn Spring Boot","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/spring-boot\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/spring-boot\/#\/schema\/person\/7f8fc5792578d2ff54003fcebe6c46b5","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/spring-boot\/author\/kindsonthegenius-3\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/posts\/82\/revisions\/86"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media\/83"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/spring-boot\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}