{"id":1465,"date":"2017-07-17T09:16:23","date_gmt":"2017-07-17T07:16:23","guid":{"rendered":"http:\/\/www.pitss.org\/blog\/?p=1465"},"modified":"2018-01-10T12:50:00","modified_gmt":"2018-01-10T11:50:00","slug":"create-and-consuming-a-restful-web-service-in-spring-boot","status":"publish","type":"post","link":"https:\/\/pitss.org\/de\/create-and-consuming-a-restful-web-service-in-spring-boot\/","title":{"rendered":"Create and Consuming a RESTful Web Service in Spring Boot"},"content":{"rendered":"<h2>What is Spring Boot<\/h2>\n<p>Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can &#8222;just run&#8220;. It take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.<\/p>\n<h2 id=\"features\">Features<\/h2>\n<ul>\n<li>Create stand-alone Spring applications<\/li>\n<li>Embed Tomcat, Jetty, WebLogic(no need to deploy WAR files)<\/li>\n<li>Provide opinionated &#8217;starter&#8216; POMs to simplify your Maven configuration<\/li>\n<li>Automatically configure Spring whenever possible<\/li>\n<li>Provide production-ready features such as metrics, health checks and externalized configuration<\/li>\n<li>Absolutely\u00a0<strong>no code generation<\/strong>\u00a0and\u00a0<strong>no requirement for XML<\/strong>\u00a0configuration<\/li>\n<\/ul>\n<h2>What you&#8217;ll need<\/h2>\n<ul>\n<li>A favorite text editor or IDE( Eclipse, Netbeans). I use for this Project Eclipse IDE<\/li>\n<li><a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html\">JDK 1.8<\/a>\u00a0or later<\/li>\n<li><a href=\"http:\/\/www.gradle.org\/downloads\">Gradle 2.3+<\/a>\u00a0or\u00a0<a href=\"https:\/\/maven.apache.org\/download.cgi\">Maven 3.0+<\/a><\/li>\n<\/ul>\n<p>I use for this Project Gradle 3.0.<\/p>\n<h2>Gradle Configuration<\/h2>\n<pre><code>buildscript {\r\n\r\next {\r\n\r\nspringBootVersion = '1.5.3.RELEASE'\r\n\r\n}\r\n\r\nrepositories {\r\n\r\nmavenCentral()\r\n\r\n}\r\n\r\ndependencies {\r\n\r\nclasspath(\"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}\")\r\n\r\n}\r\n\r\n}\r\n\r\napply plugin: 'java'\r\n\r\napply plugin: 'eclipse'\r\n\r\napply plugin: 'org.springframework.boot'\r\n\r\nversion = '0.0.1-SNAPSHOT'\r\n\r\nsourceCompatibility = 1.8\r\n\r\nrepositories {\r\n\r\nmavenCentral()\r\n\r\n}\r\n\r\ndependencies {\r\n\r\ncompile('org.springframework.boot:spring-boot-starter-data-jpa')\r\n\r\ncompile('org.springframework.boot:spring-boot-starter-web')\r\n\r\n\u00a0\r\n\r\ncompile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.0.pr3'\r\n\r\ncompile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.0.0'\r\n\r\ncompileOnly('org.projectlombok:lombok')\r\n\r\ncompile group: 'javax.servlet', name: 'jstl', version: '1.2'\r\n\r\ncompile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '9.0.0.M21'\r\n\r\ncompile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.5.3.RELEASE'\r\n\r\ntestCompile('org.springframework.boot:spring-boot-starter-test')\r\n\r\ncompile group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'\r\n\r\n}\r\n<\/code><\/pre>\n<h2>The Model<!-- HTML generated using hilite.me --><\/h2>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> io<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">blackground<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jobfinder<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">models<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #888888;\">\/**<\/span>\r\n<span style=\"color: #888888;\">* @author yotti<\/span>\r\n<span style=\"color: #888888;\">*<\/span>\r\n<span style=\"color: #888888;\">*\/<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.Entity<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.GeneratedValue<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.GenerationType<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.Id<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.JoinColumn<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.ManyToOne<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">javax.persistence.OneToOne<\/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;\">lombok.Getter<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">lombok.Setter<\/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.Date<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@Getter<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@Setter<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@Entity<\/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;\">Job<\/span> <span style=\"color: #333333;\">{<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@Id<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@GeneratedValue<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #333399; font-weight: bold;\">long<\/span> id<span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> String position<span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> String description<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #333399; font-weight: bold;\">int<\/span> minimumExperienceYears<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #333399; font-weight: bold;\">long<\/span> category<span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> String minimumDegree<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #333399; font-weight: bold;\">int<\/span> slots<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> String title<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> String image<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #333399; font-weight: bold;\">long<\/span> contrat<span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> Date published<span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #888888;\">\/\/private transient Company company;<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@ManyToOne<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">private<\/span> Company company<span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #333333;\">}<\/span><\/pre>\n<\/div>\n<h2>The Repository<!-- HTML generated using hilite.me --><\/h2>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> io<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">blackground<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jobfinder<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">Repository<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">java.util.ArrayList<\/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.data.repository.CrudRepository<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.models.Job<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n\r\n\r\n<span style=\"color: #888888;\">\/**<\/span>\r\n<span style=\"color: #888888;\"> * @author yotti<\/span>\r\n<span style=\"color: #888888;\"> *<\/span>\r\n<span style=\"color: #888888;\"> *\/<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #008800; font-weight: bold;\">interface<\/span> <span style=\"color: #bb0066; font-weight: bold;\">JobRepository<\/span> <span style=\"color: #008800; font-weight: bold;\">extends<\/span> CrudRepository<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">,<\/span> Long<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobsByTitle<\/span><span style=\"color: #333333;\">(<\/span>String title<span style=\"color: #333333;\">);<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findByTitleContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>String title<span style=\"color: #333333;\">);<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobsByCompanyCityContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>String city<span style=\"color: #333333;\">);<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobsByCompanyCityContainingIgnoreCaseAndTitleContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>String city<span style=\"color: #333333;\">,<\/span>String title<span style=\"color: #333333;\">);<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findTop2ByOrderByIdDesc<\/span><span style=\"color: #333333;\">();<\/span>\r\n\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findTop20ByOrderByIdDesc<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #888888;\">\/\/Job findByLocation(String location);<\/span>\r\n<span style=\"color: #333333;\">}<\/span><\/pre>\n<\/div>\n<h2>The Service<!-- HTML generated using hilite.me --><\/h2>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> io<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">blackground<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jobfinder<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">services<\/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.List<\/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.ArrayList<\/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;\">javax.transaction.Transactional<\/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.hibernate.Criteria<\/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.hibernate.Session<\/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.hibernate.criterion.Restrictions<\/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.beans.factory.annotation.Autowired<\/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.data.domain.Pageable<\/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.data.jpa.repository.Query<\/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.data.repository.query.Param<\/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.security.core.Authentication<\/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.security.core.context.SecurityContextHolder<\/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.stereotype.Service<\/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;\">io.blackground.jobfinder.Repository.JobRepository<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.Repository.PaginatedJobRepository<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.models.Company<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.models.Industry<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.models.Job<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.models.User<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #888888;\">\/**<\/span>\r\n<span style=\"color: #888888;\"> * @author yotti<\/span>\r\n<span style=\"color: #888888;\"> *<\/span>\r\n<span style=\"color: #888888;\"> *\/<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@Service<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@Transactional<\/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;\">JobService<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> <span style=\"color: #008800; font-weight: bold;\">final<\/span> JobRepository jobRepository<span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> UserServiceImpl userService<span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> CompanyService companyService<span style=\"color: #333333;\">;<\/span>\r\n\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span>  PaginatedJobRepository paginatedJobRepository<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #888888;\">\/**<\/span>\r\n<span style=\"color: #888888;\">\t * @param taskRepository<\/span>\r\n<span style=\"color: #888888;\">\t *\/<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #0066bb; font-weight: bold;\">JobService<\/span><span style=\"color: #333333;\">(<\/span>JobRepository jobRepository<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">super<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">this<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jobRepository<\/span> <span style=\"color: #333333;\">=<\/span> jobRepository<span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findAll<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> jobs <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span> <span style=\"color: #333333;\">(<\/span>Job job <span style=\"color: #333333;\">:<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">())<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\tjobs<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">add<\/span><span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">);<\/span>\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobs<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findAllJobsByTitle<\/span><span style=\"color: #333333;\">(<\/span>String title<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> jobs <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span> <span style=\"color: #333333;\">(<\/span>Job job <span style=\"color: #333333;\">:<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">())<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span> <span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getTitle<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">equals<\/span><span style=\"color: #333333;\">(<\/span>title<span style=\"color: #333333;\">))<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\tjobs<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">add<\/span><span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobs<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findAllJobsByCity<\/span><span style=\"color: #333333;\">(<\/span>String city<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> jobs <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span> <span style=\"color: #333333;\">(<\/span>Job job <span style=\"color: #333333;\">:<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">())<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span> <span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getCompany<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">getCity<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">toUpperCase<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>city<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">toUpperCase<\/span><span style=\"color: #333333;\">()))<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\tjobs<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">add<\/span><span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobs<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findAllJobsByCityandTitle<\/span><span style=\"color: #333333;\">(<\/span>String city<span style=\"color: #333333;\">,<\/span> String title<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> jobs <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span> <span style=\"color: #333333;\">(<\/span>Job job <span style=\"color: #333333;\">:<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">())<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span> <span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getCompany<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">getCity<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">toUpperCase<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>city<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">toUpperCase<\/span><span style=\"color: #333333;\">())<\/span>\r\n\t\t\t\t\t<span style=\"color: #333333;\">&amp;&amp;<\/span> job<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getTitle<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">toUpperCase<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">contains<\/span><span style=\"color: #333333;\">(<\/span>title<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">toUpperCase<\/span><span style=\"color: #333333;\">()))<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\tjobs<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">add<\/span><span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobs<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">save<\/span><span style=\"color: #333333;\">(<\/span>Job task<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tjobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">save<\/span><span style=\"color: #333333;\">(<\/span>task<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">delete<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">long<\/span> id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tjobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">delete<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> Job <span style=\"color: #0066bb; font-weight: bold;\">findJobById<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #333399; font-weight: bold;\">long<\/span> id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findOne<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobByCompany<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tAuthentication authentication <span style=\"color: #333333;\">=<\/span> SecurityContextHolder<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getContext<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">getAuthentication<\/span><span style=\"color: #333333;\">();<\/span>\r\n\r\n\t\tUser user <span style=\"color: #333333;\">=<\/span> userService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findByUsername<\/span><span style=\"color: #333333;\">(<\/span>authentication<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getName<\/span><span style=\"color: #333333;\">());<\/span>\r\n\t\tCompany userCompany <span style=\"color: #333333;\">=<\/span> companyService<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findCompany<\/span><span style=\"color: #333333;\">(<\/span>user<span style=\"color: #333333;\">);<\/span>\r\n\t\tList<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> jobs <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">new<\/span> ArrayList<span style=\"color: #333333;\">&lt;&gt;();<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">for<\/span> <span style=\"color: #333333;\">(<\/span>Job job <span style=\"color: #333333;\">:<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">())<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold;\">if<\/span> <span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getCompany<\/span><span style=\"color: #333333;\">().<\/span><span style=\"color: #0000cc;\">getId<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">==<\/span> userCompany<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">getId<\/span><span style=\"color: #333333;\">())<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t\t\tjobs<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">add<\/span><span style=\"color: #333333;\">(<\/span>job<span style=\"color: #333333;\">);<\/span>\r\n\t\t\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t\t<span style=\"color: #333333;\">}<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobs<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobsByTitle<\/span><span style=\"color: #333333;\">(<\/span>String title<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findJobsByTitle<\/span><span style=\"color: #333333;\">(<\/span>title<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findByTitleContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>String title<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findByTitleContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>title<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobsByCompanyCityContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>String city<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findJobsByCompanyCityContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>city<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findJobsByCompanyCityContainingIgnoreCaseAndTitleContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>String city<span style=\"color: #333333;\">,<\/span> String title<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findJobsByCompanyCityContainingIgnoreCaseAndTitleContainingIgnoreCase<\/span><span style=\"color: #333333;\">(<\/span>city<span style=\"color: #333333;\">,<\/span>title<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findTop2ByOrderByIdDesc<\/span><span style=\"color: #333333;\">(){<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findTop2ByOrderByIdDesc<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">findTop20ByOrderByIdDesc<\/span><span style=\"color: #333333;\">(){<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobRepository<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findTop20ByOrderByIdDesc<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\t\r\n\r\n<span style=\"color: #333333;\">}<\/span><\/pre>\n<\/div>\n<h2>The RestController<!-- HTML generated using hilite.me --><\/h2>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/**<\/span>\r\n<span style=\"color: #888888;\"> * <\/span>\r\n<span style=\"color: #888888;\"> *\/<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">package<\/span> io<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">blackground<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">jobfinder<\/span><span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">controller<\/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.ArrayList<\/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.beans.factory.annotation.Autowired<\/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.data.domain.Page<\/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.data.domain.Pageable<\/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.PathVariable<\/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.RequestBody<\/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.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.RequestMethod<\/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;\">io.blackground.jobfinder.models.Job<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.services.JobService<\/span><span style=\"color: #333333;\">;<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold;\">io.blackground.jobfinder.services.PaginatedJobService<\/span><span style=\"color: #333333;\">;<\/span>\r\n\r\n<span style=\"color: #888888;\">\/**<\/span>\r\n<span style=\"color: #888888;\"> * @author yotti<\/span>\r\n<span style=\"color: #888888;\"> *<\/span>\r\n<span style=\"color: #888888;\"> *\/<\/span>\r\n\r\n<span style=\"color: #555555; font-weight: bold;\">@org.springframework.web.bind.annotation.RestController<\/span>\r\n<span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"\/meinejobs\"<\/span><span style=\"color: #333333;\">)<\/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;\">RestController<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> JobService jobservice<span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #555555; font-weight: bold;\">@Autowired<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">private<\/span> PaginatedJobService paginatedJobService<span style=\"color: #333333;\">;<\/span>\r\n\r\n\t<span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>method <span style=\"color: #333333;\">=<\/span> RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">GET<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> List<span style=\"color: #333333;\">&lt;<\/span>Job<span style=\"color: #333333;\">&gt;<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAll<\/span><span style=\"color: #333333;\">()<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold;\">return<\/span> jobservice<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">findAll<\/span><span style=\"color: #333333;\">();<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>method <span style=\"color: #333333;\">=<\/span> RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">POST<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> Job <span style=\"color: #0066bb; font-weight: bold;\">create<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> Job contact<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=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>method <span style=\"color: #333333;\">=<\/span> RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">DELETE<\/span><span style=\"color: #333333;\">,<\/span> value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"{id}\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> <span style=\"color: #333399; font-weight: bold;\">void<\/span> <span style=\"color: #0066bb; font-weight: bold;\">delete<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> Long id<span style=\"color: #333333;\">)<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\t\tjobservice<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">delete<\/span><span style=\"color: #333333;\">(<\/span>id<span style=\"color: #333333;\">);<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t<span style=\"color: #555555; font-weight: bold;\">@RequestMapping<\/span><span style=\"color: #333333;\">(<\/span>method <span style=\"color: #333333;\">=<\/span> RequestMethod<span style=\"color: #333333;\">.<\/span><span style=\"color: #0000cc;\">PUT<\/span><span style=\"color: #333333;\">,<\/span> value <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"{id}\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold;\">public<\/span> Job <span style=\"color: #0066bb; font-weight: bold;\">update<\/span><span style=\"color: #333333;\">(<\/span><span style=\"color: #555555; font-weight: bold;\">@PathVariable<\/span> String id<span style=\"color: #333333;\">,<\/span> <span style=\"color: #555555; font-weight: bold;\">@RequestBody<\/span> Job contact<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=\"color: #008800; font-weight: bold;\">null<\/span><span style=\"color: #333333;\">;<\/span>\r\n\t<span style=\"color: #333333;\">}<\/span>\r\n\r\n\t\r\n\r\n<span style=\"color: #333333;\">}<\/span><\/pre>\n<\/div>\n<p>The RestController class, is the class that help to create Rest Webservices in Spring Boot.Spring 4.0 introduced @RestController, a specialized version of the controller which is a convenience annotation that does nothing more than add the @Controller and @ResponseBody annotations. By annotating the controller class with @RestController annotation, you no longer need to add @ResponseBody to all the request mapping methods. The @ResponseBody annotation is active by default. Click\u00a0<a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/javadoc-api\/org\/springframework\/web\/bind\/annotation\/RestController.html\" target=\"_blank\" rel=\"noopener\">here<\/a>\u00a0to learn more.<\/p>\n<h2>Demo<\/h2>\n<p>The Demo Url for the Rest Services is<\/p>\n<p><code>https:\/\/jobfind-master.herokuapp.com\/meinejobs<\/code><\/p>\n<p>You can use Postman to test it:<\/p>\n<h2>Source code<\/h2>\n<p><code>https:\/\/github.com\/allipierre\/JOBSPRING.git<br \/>\n<\/code><\/p>\n<p>In the Next Tutorial, we will see, how to consume this Rest Webservices in Spring using as View JSP.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Spring Boot Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can &#8222;just run&#8220;. It take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration. Features Create stand-alone Spring applications [&hellip;]<\/p>\n","protected":false},"author":46,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[85,86,81,91,92],"tags":[93,94,88,95],"class_list":["post-1465","post","type-post","status-publish","format-standard","hentry","category-java","category-jdk-7","category-tech-blog","category-web-service","category-webservice","tag-grade","tag-java","tag-rest-webservices","tag-spring-boot"],"_links":{"self":[{"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/posts\/1465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/comments?post=1465"}],"version-history":[{"count":5,"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/posts\/1465\/revisions"}],"predecessor-version":[{"id":18858,"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/posts\/1465\/revisions\/18858"}],"wp:attachment":[{"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/media?parent=1465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/categories?post=1465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pitss.org\/de\/wp-json\/wp\/v2\/tags?post=1465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}