2017-11-26 19 views
-1

私はAndroidにモバイルアプリケーションを作成しています。 Tomcatサーバーがあり、SpringBootとSpringData JPAを使用しています。 Androidをサーバーに接続するには、Retrofitを使用します。私は新人だから、パッチを使ってデータベースを更新する方法を教えてもらえますか?私は、コントローラを持っている: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>{ 

} 

とAndroidから:

public interface StudentClient { 
@PATCH("student") 

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

が不足しているものはありますか?どこにでもJPAに何かを追加する必要がありますか?

+0

欠落しているかどうかはわかりません。あなたは私たちに言います。何か間違いはありますか?期待どおりに動作しないものはありますか? –

+0

なぜあなたはPATCHを使いたいのですか?追加/更新のために 'POST/PUT'を使うべきです – Saravana

答えて