供给方组件: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241225/912a4d65dfb47ed66a751413d891187e.png) 注入方组件: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241225/9fb97814a6bcfdd93cd6e7196090b19f.png) 浏览器中可以正常展示: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241225/cd66918686d3f0e80d5a84fc46972532.png) 但是如果在供给方组件中,更换ElMessage和provide的顺序,如下图: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241225/86ca8cde42c6c08eafb7241dd9f1bd62.png) 浏览器中就无法正常渲染,并且控制台报警告: "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241225/9d4af2f010ea244a52db6c243b5a9d49.png) 请问这是什么原因呢? 备注: "element-plus": "^2.3.12" "vue": "^3.3.4"
如何在VO或者Entity类中调用springboot中的依赖注入? 情况是这样的,我有个PostVO类,其中有个catids属性需要通过另一个属性catid递归得到。我把方法写到了service的实现类(CatServiceImpl)里,然后在PostVO里调用。结果出问题了:CatServiceImpl必须交给springboot的ioc容器管理才行,不然mybatis-plus就没法用,这就意味着不能new,只能在PostVO中注入CatServiceImpl,这导致了报错,无法把PostVO封装成json(可能是因为其注入了CatService的实现类的原因),报错如下: 2024-06-08T12:25:05.100+08:00 WARN 4712 --- [blog] [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Type kotlin.reflect.KProperty1 not present] PostVO.java代码如下: // 文章展示类 @Data @Component public class PostVO { @Autowired private ICatService catService; private Integer postid; // 标题 private String title; // 分类id private Integer catid; // 级联分类ids(为了兼容element-plus的Cascader组件) private Integer[] catids; // 内容 private String content; private String thumb; private int posttime; private int updatetime; private short status; public void setCatid(Integer catid){ this.catid = catid; // 获取id集合 List parentIds = catService.getParentIds(catid); // 反转结果集 Collections.reverse(parentIds); // 将结果以数组形式付给VO的catids this.catids = parentIds.toArray(new Integer[0]); } } PostsController.java中相关代码如下: /** * 根据id返回文章(未作权限处理) * * @param id * @return */ @GetMapping("/{postid}") public Result view(@PathVariable Integer postid) { Post post = postService.getById(postid); if (post != null) { // PostVO postVO = new PostVO(); BeanUtils.copyProperties(post, postVO); System.out.println(postVO); // // 获取id集合 // List parentIds = catService.getParentIds(post.getCatid()); // // 反转结果集 // Collections.reverse(parentIds); // // 将结果以数组形式付给VO的catids // postVO.setCatids(parentIds.toArray(new Integer[0])); return Result.success(postVO); } else { return Result.fail(ResultCodeEnum.NOT_FOUND); } } 打印结果如下: PostVO(catService=com.test.blog.service.impl.CatServiceImpl@52f90432, postid=22, title=我是标题哈哈哈, catid=11, catids=[2, 6, 11], content=我是内容啦啦啦啦啦啦啦啦啦, thumb=, posttime=0, updatetime=0, status=1) 之前我是把赋值放到controller里的,但是每次返回PostVO的时候都要写一遍,就想放到PostVO里,结果就出现了上面的问题。请大佬们解惑,我这种做法不对吗?不应该写到实体类中那应该写哪?