博主
258
258
258
258
专辑

第五节 使用HuTool工具的反射工具类

亮子 2023-11-25 14:44:47 6467 0 0 0
    @ApiOperation("ReflectUtil使用:JAVA反射工具类")
    @GetMapping("/reflectUtil")
    public CommonResult reflectUtil(){
        //获取某个类的所有方法
        Method[] methods = ReflectUtil.getMethods(PmsBrand.class);
        //获取某个类的指定方法
        Method method = ReflectUtil.getMethod(PmsBrand.class, "getId");
        //通过反射来创建对象
        PmsBrand pmsBrand = ReflectUtil.newInstance(PmsBrand.class);
        //反射执行对象的方法
        ReflectUtil.invoke(pmsBrand,"setId",1);
        return CommonResult.success(null,"操作成功!");
    }