Spring ile Restful WebServis kullanımı
Merhaba arkadaşlar , Spring ile rest servisler nasıl kullanılıyor ona değineceğiz. Projemizi Maven ile açıyoruz ve gerekli kütüphaneleri pom.xml dosyamıza ekliyoruz. pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.turkishh</groupId> <artifactId>SpringRestFul</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>SpringRestFul Json Webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>3.2.2.RELEASE</spring.version> <jackson.version>1.9.10</jackson.version> <jdk.version>1.6</jdk.version> </properties> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>1.7.1</version> </dependency> </dependencies> <build> <finalName>SpringRestFul</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <downloadSources>true</downloadSources> <downloadJavadocs>false</downloadJavadocs> <wtpversion>2.0</wtpversion> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> </plugins> </build> </project> |
Varsayalım ki Company isiminde bir modelimiz olsun . Company.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package com.turkishh.model; public class Company { String name; String departments[]; public String getName() { return name; } public void setName(String name) { this.name = name; } public String[] getDepartments() { return departments; } public void setDepartments(String[] departments) { this.departments = departments; } public Company() { } } |
Rest Servis...