Skip to main content

Rest api - student - without DB



Pom.xml :-

 <!-- Dependencies for swagger -->
  <dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.5.0</version>
  </dependency>
  <dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>2.5.0</version>
  </dependency>
 
 
 Application.java : -

 1. place bellow imports : -
 ---------------------------
 import static com.google.common.collect.Lists.newArrayList;
import static springfox.documentation.schema.AlternateTypeRules.newRule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.async.DeferredResult;

import com.fasterxml.classmate.TypeResolver;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.WildcardType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

2.add @EnableSwagger2 annotation in class level
3.add this code bellow main method
----------------------------
@Autowired
private TypeResolver typeResolver;

@Bean
public Docket pcfgradleApi() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build().pathMapping("/").genericModelSubstitutes(ResponseEntity.class)
.alternateTypeRules(newRule(
typeResolver.resolve(DeferredResult.class,
typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
typeResolver.resolve(WildcardType.class)))
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500)
.message("500 message").responseModel(new ModelRef("Error")).build()));
}






-----------------------------------------------------------------------------------------------------------------------
public class Student {

 public String name;
 public int id;
}



----------------
import com.wfd.springDemo.model.Student;

@RestController
@RequestMapping("/newstudent")
public class StudentController {

static Student student;

@RequestMapping(method=RequestMethod.POST)
public Student createStudent(@RequestBody Student student){
this.student=student;
return this.student;
}

@RequestMapping(method=RequestMethod.PUT)
public Student putStudent(@RequestBody Student student){
this.student=student;
return this.student;
}

@RequestMapping(method=RequestMethod.DELETE)
public Student deleteStudent(){
this.student=null;
return this.student;
}

@RequestMapping(method=RequestMethod.GET)
public Student getStudent(){
return this.student;
}
//Create - POST
//Update - Put
//Delete - delete
//Fetch  - Get
}


Comments

Popular posts from this blog

Tell me about yourself

                            About you My name is xyz. I am from Ap currently living in BLR from 7 years I did my B Tech graduation from JNT university on xxx year About Career I have started my career with xyz company as Junior developer working on xyz technologies Currently I am working on xyz project. Technologies  The technologies which are being used are Angular, Spring, Springboot, restful web-service and SQL Roles & Responsibilities  My role and responsibilities are on Back-end/FE development. BE/FE development: We are using so and so technologies for BE/FE development I am working on xyz layers in BE/FE development Achievements & Training's  

Repository - Git

                                              Repository              is a central place in which an data is kept and maintained in an organised  and characterized way in storage of computer. EXAMPLES Start a new Git repository for an existing code base $ cd /path/to/my/codebase $ git init (1) $ git add . (2) $ git commit (3) Create a /path/to/my/codebase/.git directory. Add all existing files to the index. Record the pristine state as the first commit in the history.

Java Training Content

                                               Java Training Contents :  Learn Computer Fundamentals -what is software Ref : https://www.techopedia.com/definition/4356/software -what is programming language, Functional Programming, OO programming Ref : https://www.geeksforgeeks.org/introduction-to-programming-languages/     : https://www.techopedia.com/definition/24815/programming-language : https://study.com/academy/lesson/what-is-programming-language-types-examples-quiz.html : https://www.youtube.com/watch?v=ifo76VyrBYo -Install JDK and set Java path -Hello world program Ref : -Compilation and interpretation Compilation : convert source code to executable code - interpreted : execute instruction line by line. -Features of Java - Platform Independent Ref : https://www.geeksforgeeks.org/java-platform-independent/ L...