2017-11-26 13 views
-1

나는 Android에 모바일 애플리케이션을 작성 중이다. SpringBoot 및 SpringData JPA를 사용하는 TomCat 서버가 있습니다. Android를 서버에 연결하기 위해 Retrofit을 사용합니다. 나는 신참이기 때문에 Patch를 사용하여 데이터베이스를 업데이트하는 방법을 알려 주실 수 있습니까?SpringDataJPA의 패치

@RestController 
@RequestMapping("/student") 
public class StudentController { 
private StudentRepository studentRepository; 

@Autowired 
public StudentController(StudentRepository studentRepository) { 
    this.studentRepository = studentRepository; 
} 



@RequestMapping(method = RequestMethod.PATCH)//dodanie 
public String updateStudent(@RequestBody Student student) 
{ 
    studentRepository.save(student); 
    return "{success:true}"; 
} 

//zwraca liste studentow 
@RequestMapping(method = RequestMethod.GET) 
public List<Student> getStudent(){ 
    return studentRepository.findAll(); 
} 
} 

JPA 저장소 :

import org.springframework.data.jpa.repository.JpaRepository; 

public interface StudentRepository extends JpaRepository<Student, Long>{ 

} 

그리고 안드로이드에서 : 실종 아무것도

public interface StudentClient { 
@PATCH("student") 

Call<Student>updateStudent(@Body Student student); 
} 

거기에 내가 컨트롤러가? 어디에서나 JPA에 추가해야합니까?

+0

누락 된 항목이 있는지 여부는 알 수 없습니다. 너 한테 말해. 오류가 있습니까? 기대했던대로 작동하지 않는 것이 있습니까? –

+0

왜 PATCH를 사용하고 싶습니까? 추가/업데이트하려면'POST/PUT'을 사용해야합니다. – Saravana

답변