spring4 获取泛型信息

谁践踏了优雅 2022-08-08 12:49 269阅读 0赞
  1. public interface TestService<Question> {
  2. public String test();
  3. }
  4. @Service
  5. public class TestServiceImpl implements TestService<Question> {
  6. @Override
  7. public String test() {
  8. String abc = "abc";
  9. return abc;
  10. }
  11. }
  12. @Controller
  13. @RequestMapping("/test")
  14. public class TestController {
  15. @Autowired
  16. private TestService<Question> testService;
  17. @RequestMapping
  18. public String index(){
  19. testService.test();
  20. ResolvableType resolvableType2 = ResolvableType.forField(ReflectionUtils.findField(TestController.class, "testService"));
  21. System.out.println(resolvableType2.getGeneric(0).resolve());
  22. return "index";
  23. }
  24. }

发表评论

表情:
评论列表 (有 0 条评论,269人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Java获取类型信息

    根据使用泛型位置的不同可以分为:声明侧泛型、使用侧泛型。 声明侧的泛型信息被记录在Class文件的Constant pool中以Signature的形式保存。而使用侧的泛型信