I try to implement a base mapper interface :
public interface IDAOBase<T, ID> {
default List<T> findAll() {
throw new RuntimeException("Method not implemented !");
}
default T findById(ID id) {
throw new RuntimeException("Method not implemented !");
}
default ID insert(T t) {
throw new RuntimeException("Method not implemented !");
}
default T update(T t) {
throw new RuntimeException("Method not implemented !");
}
default void delete(ID id) {
throw new RuntimeException("Method not implemented !");
}
default T getRowById(ID id) {
throw new RuntimeException("Method not implemented !");
}
}
This would be a mapper that extends the base interface :
@Mapper
interface UserMapper extends IDAOBase<UserVO, Long> {
UserVO findByUsername(String username);
// UserVO findById(Long id);
}
I invoke the mapper like this :
@Autowired
private UserMapper mapper;
public UserDetails loadUserById(Long id) {
return loadUser(mapper.findById(id));
}
But I get a RuntimeException thrown from the default method :
java.lang.RuntimeException: Method not implemented !
at com.project.services.IDAOBase.findById(IDAOBase.java:8)
in xml I have the "findById" method:
<select id="findById"
resultType="UserVO">
<include refid="baseSelect"/>
where
k.id = #{id}
</select>
Also; when I uncomment this line in mapper interface it works :
This works :
@Mapper
interface UserMapper extends IDAOBase<UserVO, Long> {
UserVO findByUsername(String username);
UserVO findById(Long id);
}
This doesn't work :
@Mapper
interface UserMapper extends IDAOBase<UserVO, Long> {
UserVO findByUsername(String username);
// UserVO findById(Long id);
}
What is the error here?