vue+springboot仓库管理系统大作业bug汇总

1.前端基于axios发送post请求,结果控制台报错:Access to XMLHttpRequest at 'http://localhost:8081/allocate/addAllocate' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

原因:跨域请求,具体原因百度。

解决:后端controller前加@CrossOrigin注解

2.使用vuex实现组件间共享数据,结果控制台报错this.$store是undefined,无法访问到共享的数据

原因:this代指的内容发生了变化,具体原因我也不清楚

解决:在函数外面定义const store=useStore(),然后在方法中以store.state.变量名,这种方式访问共享数据。

我在使用router时遇到了同样的问题,原因大概与此相同,解决方法也一致,只不过此时定义为const router=useRouter()。

3.使用JSONObject.parseArray方法进行数组转换,有的数据能正常读取,而有的却不行。

List<allocateitems> newItems= JSONObject.parseArray(JSON.toJSONString(map.get("data")) , allocateitems.class);

我的实体类中包含了goodID,num两个属性,除了名字外完全一样(包括数据类型,前端传回来的数据类型),结果goodID无论怎么都读不进来,而num却正常。

解决:修改实体类的名称good为goodId。

4.由于id设置成自增,难以获取条目的id,从而与其它表格中的条目建立映射关系。

解决:

            allocateMapper.insert(newAllocate);//先插入表格
            int allocate_id=newAllocate.getId();//获取自动修改的id
            for (allocateitems tmp: newItems) {
                tmp.setAllocate_id(allocate_id);
            }

先将数据插入表格,此时变量的id自动修改成了自增id,再获取就好了。

猜你喜欢

转载自blog.csdn.net/qq_16198739/article/details/128008641