Crud Operation API calling Using Postman

 package com.example.task.demo;


import java.util.ArrayList;


import org.springframework.web.bind.annotation.DeleteMapping;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PutMapping;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RestController;








@RestController

public class StudentController {

ArrayList<Student>aa=new ArrayList<Student>();

/* Using Constuctor*/ 

public StudentController(){

aa.add(new Student(401, "Ganesh"));

aa.add(new Student(402, "Shreyash"));

aa.add(new Student(401, "Aniket"));

aa.add(new Student(401, "Darshan"));


}

@GetMapping("all")

public ArrayList<Student> All(){

return aa;

}

@GetMapping("singleRecord/{id}") // requestapi // 101

public Student singleRecord(@PathVariable int id) {

Student ss = new Student();

// get(id);

// load


for (Student student : aa) {

if (student.id == id) {

ss = student;

}

}

return ss;

}

@GetMapping("single student")

public Student single(@RequestBody int id) {// 101

Student ss = new Student();

for (Student student : aa) {

if (student.id == id) {

ss = student;

}

}

return ss;

}

@PutMapping("updateRecord")

public ArrayList<Student> update(@RequestBody Student student) {

Student ss = new Student();

for (Student student2 : aa) {

if (student2.id == student.id) {

ss = student2;

}

}


// ss.update(student);


ss.setId(student.id);

ss.setName(student.name);

return aa;

}

@DeleteMapping("deleteSingleRecord/{id}") // requestapi // 101

public ArrayList<Student> deleteSingleRecord(@PathVariable int id) {

Student ss = new Student();

for (Student student : aa) {

if (student.id == id) {

ss = student;

}

}


// ss.delete(student);

aa.remove(ss);

return aa;

}



}


Comments

Popular posts from this blog

Hello World Program In Flutter using Android Studio.

what is Angular Architecture ?

Java Notes