能不能定义接口时,接受参数。这个参数做为接口中方法的返回类型?
比如:
/ 定义一个能接受参数的接口 /
public interface MyInterface<T>{
/* 把这个参数作为方法返回类型 */
public List<T> method();
}
问题来自与SPRINGBOOT,service调用dao.find方法,返回总是list<String>,因为dao使用@mapper是接口,我想把对象转入,使其它方法返回list<对象>。
能不能定义接口时,接受参数。这个参数做为接口中方法的返回类型?
比如:
/ 定义一个能接受参数的接口 /
public interface MyInterface<T>{
/* 把这个参数作为方法返回类型 */
public List<T> method();
}
问题来自与SPRINGBOOT,service调用dao.find方法,返回总是list<String>,因为dao使用@mapper是接口,我想把对象转入,使其它方法返回list<对象>。
可以考虑这样:
public interface BaseMapper<T> {
public List<T> method();
}
@Mapper
public interface Impl extends BaseMapper<Student> {}
我觉得问题的关键在于dao接口没有显式的实现类,T类型因此没有传入的位置,另外返回String的问题,建议附上mapper.xml,主要关注一下resultType或resultMap的内容。
希望能帮到你。
15 回答8.4k 阅读
8 回答6.2k 阅读
3 回答3.6k 阅读✓ 已解决
1 回答4k 阅读✓ 已解决
3 回答6k 阅读
3 回答2.6k 阅读✓ 已解决
3 回答2.2k 阅读✓ 已解决
可以的
但是如果 dao 层 接口的方法返回 list<Student> 这种
可以直接这样的昂