Last active
July 31, 2021 18:56
-
-
Save Francisco-Castillo/226258c524ce760ba4c99e280d504936 to your computer and use it in GitHub Desktop.
Spring boot stored procedure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE PROCEDURE student_leave(studentId number) | |
LANGUAGE plpgsql | |
AS $procedure$ | |
begin | |
UPDATE student | |
SET status = 1 WHERE id = studentId; | |
end; $procedure$ | |
; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Repository | |
public interface StudentRepository extends JpaRepository<StudentEntity, Long> { | |
// ... | |
@Transactional | |
@Modifying | |
@Query(value = "CALL student_leave(:studentId);", nativeQuery = true) | |
public void studentLeave(@Param("studentId") Long studentId); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
@Service | |
public class StudentService { | |
@Autowired | |
private StudentRepository studentRepository; | |
public ResponseEntity<Object> update(Long studentId){ | |
try{ | |
// Ejecutamos el SP | |
studentRepository.studentLeave(studentId); | |
}catch(){ | |
//... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ejecutar procedimiento almacenado en Spring boot