Это контроллер класса
package Controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.model.Person;
import com.example.demo.service.PersonService;
@RestController
public class PersonController {
@Autowired
private PersonService personService;
@RequestMapping("/create")
public String create(@RequestParam String fname,@RequestParam String lname,@RequestParam int age)
{
Person p = personService.create(fname, lname, age);
return p.toString();
}
@RequestMapping("/get")
public Person getPerson(@RequestParam String fname)
{
return personService.getByFirstName(fname);
}
@RequestMapping("/getAll")
public List<Person> getAll()
{
return personService.getAll();
}
@RequestMapping("/update")
public Person update(@RequestParam String fname,@RequestParam String lname,@RequestParam int age)
{
Person p = personService.update(fname, lname, age);
return p;
}
@RequestMapping("/delete")
public void deleteByName(@RequestParam String fname)
{
personService.delete(fname);
}
@RequestMapping("/deleteAll")
public void deleteAll()
{
personService.deleteAll();
}
}
это еще один пример
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RestController
public class CourseTotalController {
@Autowired
CourseTotalRepository repository;
@Autowired
SubjectRepository SubRepository;
@RequestMapping(value = "/total/{id}", method = RequestMethod.GET)
public Courses calcTotal(@PathVariable("id") String id) {
float total = 0;
Optional<Courses> opt = repository.findById(id);
Courses modifiedCourse = opt.get();
String [] Subjects = opt.get().getSubjects();
for(int i=0;i< Subjects.length;i++) {
Optional<Subject> SubjectOpt = SubRepository.findById(Subjects[i]);
total = total + SubjectOpt.get().getAmount();
}
modifiedCourse.setTotal(total);
return modifiedCourse;
}
}