-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に何かを追加する必要がありますか?
欠落しているかどうかはわかりません。あなたは私たちに言います。何か間違いはありますか?期待どおりに動作しないものはありますか? –
なぜあなたはPATCHを使いたいのですか?追加/更新のために 'POST/PUT'を使うべきです – Saravana