• 医院项目-预约挂号-第六部分(医院管理排班和网关)


    一、排班管理:

    1、页面效果:

    在这里插入图片描述

    排班分成三部分显示:
    1、科室信息(大科室与小科室树形展示)
    2、排班日期,分页显示,根据上传排班数据聚合统计产生
    3、排班日期对应的就诊医生信息

    2、接口分析:

    1,科室数据使用Element-ui el-tree组件渲染展示,需要将医院上传的科室数据封装成两层父子级数据;
    2,聚合所有排班数据,按日期分页展示,并统计号源数据展示;
    3,根据排班日期获取排班详情数据

    3、实现分析
    虽然是一个页面展示所有内容,但是页面相对复杂,我们分步骤实现
    1,先实现左侧科室树形展示;
    2,其次排班日期分页展示
    3,最后根据排班日期获取排班详情数据

    在这里插入图片描述

    在这里插入图片描述

    二、排班管理实现:

    1、科室列表

    1.1 后端api接口

    在这里插入图片描述

    controller:
    这里为何要用DepartmentVo类作为泛型,因为此DepartmentVo类有一个子属性List children;用来封装子科室;

    在这里插入图片描述

    在这里插入图片描述

    实现类:

    //根据医院编号,查询医院所有科室列表
    @Override
    public List findDeptTree(String hoscode) {
        //创建list集合,用于最终数据封装
        List result = new ArrayList<>();
    
        //根据医院编号,查询医院所有科室信息
        Department departmentQuery = new Department();
        departmentQuery.setHoscode(hoscode);
        Example example = Example.of(departmentQuery);
        //所有科室列表 departmentList
        List departmentList = departmentRepository.findAll(example);
    
        //根据大科室编号  bigcode 分组,获取每个大科室里面下级子科室
        Map> deparmentMap =
                departmentList.stream().collect(
                Collectors.groupingBy(Department::getBigcode));
        //遍历map集合 deparmentMap
        for(Map.Entry> entry : deparmentMap.entrySet()) {
            //大科室编号
            String bigcode = entry.getKey();
            //大科室编号对应的全局数据
            List deparment1List = entry.getValue();
            //封装大科室
            DepartmentVo departmentVo1 = new DepartmentVo();
            departmentVo1.setDepcode(bigcode);
            departmentVo1.setDepname(deparment1List.get(0).getBigname());
    
            //封装小科室
            List children = new ArrayList<>();
            for(Department department: deparment1List) {
                DepartmentVo departmentVo2 =  new DepartmentVo();
                departmentVo2.setDepcode(department.getDepcode());
                departmentVo2.setDepname(department.getDepname());
                //封装到list集合
                children.add(departmentVo2);
            }
            //把小科室list集合放到大科室children里面
            departmentVo1.setChildren(children);
            //放到最终result里面
            result.add(departmentVo1);
        }
        //返回
        return result;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45

    swagger测试:

    在这里插入图片描述

    1.2 科室前端:

    1.2.1 添加路由
    在 src/router/index.js 文件添加排班隐藏路由

    在这里插入图片描述

    {
      path: 'hospital/schedule/:hoscode',
      name: '排班',
      component: () => import('@/views/hosp/schedule'),
      meta: { title: '排班', noCache: true },
      hidden: true
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    1.2.2 添加按钮
    在医院列表页面,添加排班按钮:

    
        排班
     
    
    • 1
    • 2
    • 3

    1.2.3封装前端api请求

         //6.排班
         getscheduleByHoscode(hoscode){
          return request({
            url: `admin/hosp/department/getDeptList_my/${hoscode}`,
            method: 'get'
         })
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    1.2.4 部门展示
    修改/views/hosp/schedule.vue组件:

    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64

    2、排班日期分页列表

    2.1 后端api接口:

    添加controller接口
    添加com.fan.yygh.hosp.controller.ScheduleController类

    在这里插入图片描述

    //根据医院编号 和 科室编号 ,查询排班规则数据
    @ApiOperation(value ="查询排班规则数据")
    @GetMapping("getScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getScheduleRule(@PathVariable long page,
                                  @PathVariable long limit,
                                  @PathVariable String hoscode,
                                  @PathVariable String depcode) {
        Map map 
    = scheduleService.getRuleSchedule(page,limit,hoscode,depcode);
        return Result.ok(map);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    在这里插入图片描述

    实现类:

    
    @Autowired
    private ScheduleRepository scheduleRepository;
    
    @Autowired
    private MongoTemplate mongoTemplate;
    
    @Autowired
    private HospitalService hospitalService;
    
    
    //根据医院编号 和 科室编号 ,查询排班规则数据
    @Override
    public Map getRuleSchedule(long page, long limit, String hoscode, String depcode) {
        //1 根据医院编号 和 科室编号 查询
        Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode);
    
        //2 根据工作日workDate期进行分组
        Aggregation agg = Aggregation.newAggregation(
                Aggregation.match(criteria),//匹配条件
                Aggregation.group("workDate")//分组字段
                .first("workDate").as("workDate")
                //3 统计号源数量
                .count().as("docCount")
                .sum("reservedNumber").as("reservedNumber")
                .sum("availableNumber").as("availableNumber"),
                //排序
                Aggregation.sort(Sort.Direction.DESC,"workDate"),
                //4 实现分页
                Aggregation.skip((page-1)*limit),
                Aggregation.limit(limit)
        );
        //调用方法,最终执行
        AggregationResults aggResults =
                mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
        List bookingScheduleRuleVoList = aggResults.getMappedResults();
    
        //分组查询的总记录数
        Aggregation totalAgg = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("workDate")
        );
        AggregationResults totalAggResults =
                mongoTemplate.aggregate(totalAgg, 
    Schedule.class, BookingScheduleRuleVo.class);
        int total = totalAggResults.getMappedResults().size();
    
        //把日期对应星期获取
        for(BookingScheduleRuleVo bookingScheduleRuleVo:bookingScheduleRuleVoList) {
            Date workDate = bookingScheduleRuleVo.getWorkDate();
            String dayOfWeek = this.getDayOfWeek(new DateTime(workDate));
            bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
        }
    
        //设置最终数据,进行返回
        Map result = new HashMap<>();
        result.put("bookingScheduleRuleList",bookingScheduleRuleVoList);
        result.put("total",total);
    
        //获取医院名称
        String hosName = hospitalService.getHospName(hoscode);
        //其他基础数据
        Map baseMap = new HashMap<>();
        baseMap.put("hosname",hosName);
        result.put("baseMap",baseMap);
    
        return result;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69

    在这里插入图片描述

    增加日期工具类:

    /**
     * 根据日期获取周几数据
     * @param dateTime
     * @return
     */
    private String getDayOfWeek(DateTime dateTime) {
        String dayOfWeek = "";
        switch (dateTime.getDayOfWeek()) {
            case DateTimeConstants.SUNDAY:
                dayOfWeek = "周日";
                break;
            case DateTimeConstants.MONDAY:
                dayOfWeek = "周一";
                break;
            case DateTimeConstants.TUESDAY:
                dayOfWeek = "周二";
                break;
            case DateTimeConstants.WEDNESDAY:
                dayOfWeek = "周三";
                break;
            case DateTimeConstants.THURSDAY:
                dayOfWeek = "周四";
                break;
            case DateTimeConstants.FRIDAY:
                dayOfWeek = "周五";
                break;
            case DateTimeConstants.SATURDAY:
                dayOfWeek = "周六";
            default:
                break;
        }
        return dayOfWeek;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    获取医院名称的实现类:
    在这里插入图片描述

    获取医院名称的实现类:

     //获取医院的名字根据医院编号
        @Override
        public String getHospName(String hoscode) {
            Hospital hospital = hospitalRepository.getHospitalByHoscode(hoscode);
            if(hospital != null){
                System.out.println(hospital.getHosname());
                return hospital.getHosname();//获取医院名称
            }
            return null;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    测试:

    在这里插入图片描述

    2.2 排班日期前端:

    1.2.1封装api请求

    在/api/hosp/schedule.js文件添加方法:

    在这里插入图片描述

     //7.查询预约规则
        getScheduleRule(page,limit,hoscode,depcode){
          return request({
            url: `admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`,
            method: 'get'
          })
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    页面展示
    修改/views/hosp/schedule.vue组件:

    export default {
        data() {
            return {
                data: [],  //后端接口返回的数据
                defaultProps: {  //子节点
                    children: 'children',
                    label: 'depname'
                },
                hoscode: null  ,//医院编号
    
                activeIndex: 0,
                depcode: null,
                depname: null,
                workDate: null,
    
                bookingScheduleList: [],
                baseMap: {},
    
                page: 1, // 当前页
                limit: 7, // 每页个数
                total: 0 // 总页码
            }
        },
        created(){
            //因为我们是通过路径来传参数hoscode。要从又有参数中获取参数hoscode
            this.hoscode = this.$route.params.hoscode;
            this.workDate = this.getCurDate();
            this.fetchData();
        },
        methods:{
           fetchData(){
            hospApi.getscheduleByHoscode(this.hoscode)
                .then( res => {
                    this.data = res.data;  //将后台数据赋值 给前台 
                    // 默认选中第一个
                        if (this.data.length > 0) {
                            this.depcode = this.data[0].children[0].depcode
                            this.depname = this.data[0].children[0].depname
    
                            this.getPage()
                        }
                })
            
           },
           getPage(page = 1) {
                this.page = page
                this.workDate = null
                this.activeIndex = 0
                this.getScheduleRule()
           },
            getScheduleRule() {
              hospApi.getScheduleRule(this.page, this.limit, this.hoscode, this.depcode)
                .then(response => {
                    this.bookingScheduleList = response.data.bookingScheduleRuleList
                    this.total = response.data.total
    
                    this.scheduleList = response.data.scheduleList
                    this.baseMap = response.data.baseMap
    
                    // 分页后workDate=null,默认选中第一个
                    if (this.workDate == null) {
                    
                        this.workDate = this.bookingScheduleList[0].workDate
                    }
                })
            },
            handleNodeClick(data) {
            // 科室大类直接返回
            if (data.children != null) return
            this.depcode = data.depcode
            this.depname = data.depname
    
            this.getPage(1)
            },
            selectDate(workDate, index) {
            this.workDate = workDate
            this.activeIndex = index
            },
            getCurDate() {
            var datetime = new Date()
            var year = datetime.getFullYear()
            var month = datetime.getMonth() + 1 < 10 ? '0' + (datetime.getMonth() + 1) : datetime.getMonth() + 1
            var date = datetime.getDate() < 10 ? '0' + datetime.getDate() : datetime.getDate()
            return year + '-' + month + '-' + date
            }
    
        }
    }
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100

    3、根据排班日期获取排班详情列表:

    添加controller:
    //根据医院编号 、科室编号和工作日期,查询排班详细信息

    在这里插入图片描述

    
    
    • 1

    实现类:

    在这里插入图片描述

    在这里插入图片描述

    //根据医院编号 、科室编号和工作日期,查询排班详细信息
    @Override
    public List getDetailSchedule(String hoscode, String depcode, String workDate) {
        //根据参数查询mongodb
        List scheduleList =
                scheduleRepository.findScheduleByHoscodeAndDepcodeAndWorkDate(hoscode,depcode,new DateTime(workDate).toDate());
        //把得到list集合遍历,向设置其他值:医院名称、科室名称、日期对应星期
        scheduleList.stream().forEach(item->{
            this.packageSchedule(item);
        });
        return scheduleList;
    }
    //封装排班详情其他值 医院名称、科室名称、日期对应星期
    private void packageSchedule(Schedule schedule) {
        //设置医院名称
        schedule.getParam().put("hosname",hospitalService.getHospName(schedule.getHoscode()));
        //设置科室名称
        schedule.getParam().put("depname",departmentService.getDepName(schedule.getHoscode(),schedule.getDepcode()));
        //设置日期对应星期
        schedule.getParam().put("dayOfWeek",this.getDayOfWeek(new DateTime(schedule.getWorkDate())));
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    在这里插入图片描述

    测试:

    在这里插入图片描述

    在这里插入图片描述

    排班详情前端:api接口

    在这里插入图片描述

      //8.查询排班详情
         getScheduleDetail(hoscode,depcode,workDate){
          return request({
            url: `admin/hosp/schedule/getScheduleDetail/${hoscode}/${depcode}/${workDate}`,
            method: 'get'
          })
        },
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    排班的详情显示组件:

    
    
        
            
        
    
        
            
        
    
        
            
        
        
        
        
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    最终的排班页面:

    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188

    三、服务网关:

    1、网关介绍

    API网关出现的原因是微服务架构的出现,不同的微服务一般会有不同的网络地址,而外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与各个微服务通信,会有以下的问题:
    (1)客户端会多次请求不同的微服务,增加了客户端的复杂性。
    (2)存在跨域请求,在一定场景下处理相对复杂。
    (3)认证复杂,每个服务都需要独立认证。
    (4)难以重构,随着项目的迭代,可能需要重新划分微服务。例如,可能将多个服务合并成一个或者将一个服务拆分成多个。如果客户端直接与微服务通信,那么重构将会很难实施。
    (5)某些微服务可能使用了防火墙 / 浏览器不友好的协议,直接访问会有一定的困难。
    以上这些问题可以借助 API 网关解决。API 网关是介于客户端和服务器端之间的中间层,所有的外部请求都会先经过API 网关这一层。也就是说,API 的实现方面更多的考虑业务逻辑,而安全、性能、监控可以交由 API 网关来做,这样既提高业务灵活性又不缺安全性

    2、Spring Cloud Gateway介绍

    Spring cloud gateway是spring官方基于Spring 5.0、Spring Boot2.0和Project Reactor等技术开发的网关,Spring Cloud Gateway旨在为微服务架构提供简单、有效和统一的API路由管理方式,Spring Cloud Gateway作为Spring Cloud生态系统中的网关,目标是替代Netflix Zuul,其不仅提供统一的路由方式,并且还基于Filer链的方式提供了网关基本的功能,例如:安全、监控/埋点、限流等

    在这里插入图片描述

    3、搭建server-gateway模块

    服务网关
    3.1 搭建server-gateway,在根工程yygh_parent下创建maven工程:
    搭建过程如common模块
    3.2 修改配置pom.xml:

    
        
            com.atguigu.yygh
            common-util
            1.0
        
    
        
            org.springframework.cloud
            spring-cloud-starter-gateway
        
    
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3.3 在resources下添加配置文件
    1、application.properties:

    # 服务端口
    server.port=80
    # 服务名
    spring.application.name=service-gateway
    
    # nacos服务地址
    spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
    
    #使用服务发现路由
    spring.cloud.gateway.discovery.locator.enabled=true
    
    #设置路由id
    spring.cloud.gateway.routes[0].id=service-hosp
    #设置路由的uri
    spring.cloud.gateway.routes[0].uri=lb://service-hosp
    #设置路由断言,代理servicerId为auth-service的/auth/路径
    spring.cloud.gateway.routes[0].predicates= Path=/*/hosp/**
    
    #设置路由id
    spring.cloud.gateway.routes[1].id=service-cmn
    #设置路由的uri
    spring.cloud.gateway.routes[1].uri=lb://service-cmn
    #设置路由断言,代理servicerId为auth-service的/auth/路径
    spring.cloud.gateway.routes[1].predicates= Path=/*/cmn/**
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    3.4添加启动类

    package com.fan.yygh;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class ServerGatewayApplication {
        public static void main(String[] args) {
            SpringApplication.run(ServerGatewayApplication.class, args);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    3.5 跨域处理
    跨域:浏览器对于javascript的同源策略的限制 。
    以下情况都属于跨域:
    在这里插入图片描述

    如果域名和端口都相同,但是请求路径不同,不属于跨域,如:
    www.jd.com/item
    www.jd.com/goods
    http和https也属于跨域
    而我们刚才是从localhost:1000去访问localhost:8888,这属于端口不同,跨域了。

    3.5.1 为什么有跨域问题?

    跨域不一定都会有跨域问题。
    因为跨域问题是浏览器对于ajax请求的一种安全限制:一个页面发起的ajax请求,只能是与当前页域名相同的路径,这能有效的阻止跨站攻击。
    因此:跨域问题 是针对ajax的一种限制。
    但是这却给我们的开发带来了不便,而且在实际生产环境中,肯定会有很多台服务器之间交互,地址和端口都可能不同,怎么办?

    3.5.2解决跨域问题:

    网关的全局配置类实现:
    CorsConfig类:

    @Configuration
    public class CorsConfig {
        @Bean
        public CorsWebFilter corsFilter() {
            CorsConfiguration config = new CorsConfiguration();
            config.addAllowedMethod("*");
            config.addAllowedOrigin("*");
            config.addAllowedHeader("*");
    
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
            source.registerCorsConfiguration("/**", config);
    
            return new CorsWebFilter(source);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    3.6服务调整
    目前我们已经在网关做了跨域处理,那么service服务就不需要再做跨域处理了,将之前在controller类上添加过@CrossOrigin标签的去掉,防止程序异常;

    3.7测试
    通过平台与管理平台前端测试

    前端这里改成 这样:
    在这里插入图片描述

    启动 三个程序去测试:

    在这里插入图片描述

    在这里插入图片描述

    测试发现排班有小问题,时间不对,点击上面日期不能显示对应的排班详细信息;

  • 相关阅读:
    [SuperSocket2.0]SuperSocket 2.0从入门到懵逼
    【libhv】udp客户端服务器简单例子
    JavaScript 笔记 初识JavaScript(变量)
    office2019在保存的时候报错
    软考高级系统架构设计师系列之:信息系统基础知识
    vs如何读取mysql中的数据(顺便通过代码解决了中文乱码问题)
    【学习笔记】尚未用过的图论知识
    uniapp中scroll-view初始化的时候 无法横向滚动到某个为止
    docker数据卷管理
    [go 面试] Go Kit中读取原始HTTP请求体的方法
  • 原文地址:https://blog.csdn.net/weixin_38568503/article/details/126355442