쿼리 메서드로 해결이 되지 않은 경우 직접 코딩으로 구현이 가능합니다
@Entity @Getter @Setter
public class Post{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@Lob
private String content;
@Temporal(TemporalType.TIMESTAMP)
private Date date;
}
public interface PostRepository extends JpaRepository<Post,Long>{
}
public interface PostCustoRepository{
List<Post> findMyPost();
}
@Repository
@Transactional
public class PostCustomRepositoryImpl implements PostCustomRepository{
@Autowired
EntityManager entityManager;
@Override
public List<Postarg> findMyPost() {
System.out.println("custom findMyPost");
return entityManager.createQuery("SELECT p FROM Postarg AS p ",Postarg.class).getResultList();
}
}
public interface PostRepository extends JpaRepository<Post,Long> ,PostCustomRepository{
}
@SpringBootTest
class PostRepositoryTest{
@Autowired
private PostRepository postRepository;
@Test
void crud(){
postRepository.findMyPost();
}
}
public interface PostCustomRepository {
List<Postarg> findMyPost();
void delete(T entity);
}