springcloud项目03

跨域

SpringMVC已经帮我们写好了CORS的跨域过滤器CorsFilter ,内部已经实现了刚才所讲的判定逻辑,我们直接用就好了。

所有前端请求都是通过zuul转发,所有在网关中加入跨越支持

@Configuration
public class GlobalCorsConfig {
    @Bean
    public CorsFilter corsFilter() {
        //1.添加CORS配置信息
        CorsConfiguration config = new CorsConfiguration();
        //1) 允许的域,不要写*,否则cookie就无法使用了
        config.addAllowedOrigin("http://127.0.0.1:6001");
config.addAllowedOrigin("http://localhost:6001");
        //2) 是否发送Cookie信息
        config.setAllowCredentials(true);
        //3) 允许的请求方式
        config.addAllowedMethod("OPTIONS");
        config.addAllowedMethod("HEAD");
        config.addAllowedMethod("GET");
        config.addAllowedMethod("PUT");
        config.addAllowedMethod("POST");
        config.addAllowedMethod("DELETE");
        config.addAllowedMethod("PATCH");
        // 4)允许的头信息
        config.addAllowedHeader("*");
        //2.添加映射路径,我们拦截一切请求
        UrlBasedCorsConfigurationSource configSource = new
                UrlBasedCorsConfigurationSource();
        configSource.registerCorsConfiguration("/**", config);
        //3.返回新的CorsFilter.
        return new CorsFilter(configSource);
    }
}

mybatisPlus高级查询和分页

处理有关联对象时

 <sql id="whereSql">
        <where>
            <if test="keyword!=null and keyword!=''">

                and t.companyName like concat('%',#{keyword},"%")
            </if>
        </where>
    </sql>
    <!--List<Tenant> loadPageList(Page<Tenant> page, TenantQuery query);-->
    <select id="loadPageList" resultMap="TenantMap">
        SELECT t.*,type.id tid,type.NAME tname,e.id eid,e.realName
        FROM t_tenant t
        LEFT JOIN t_tenant_type type ON t.tenant_type = type.id
        LEFT JOIN t_employee e on t.id = e.tenant_id
        <include refid="whereSql"></include>
    </select>
<resultMap id="TenantMap" type="Tenant">
        <id column="id" property="id" />
        <result column="tenant_type" property="tenantType" />
        <result column="companyName" property="companyName" />
        <result column="companyNum" property="companyNum" />
        <result column="registerTime" property="registerTime" />
        <result column="state" property="state" />
        <result column="address" property="address" />
        <result column="logo" property="logo" />

        <!-- 机构类型多对一关联-->
        <association property="type" javaType="TenantType">
            <id column="tid" property="id" />
            <result column="tname" property="name" />
        </association>

        <!--管理员的关联查询-->
        <association property="admin" javaType="Employee">
            <id column="eid" property="id" />
            <result column="realName" property="realName" />

        </association>

处理没有关联对象时

 <sql id="whereSql">
        <where>
            <if test="keyword!=null and keyword!=''">
                and (name like concat('%',#{keyword},'%') or description like concat('%',#{keyword},'%'))
            </if>
        </where>
    </sql>
    <!--
       List<TenantType> loadPageLiset(Page<TenantType> page, TenantTypeQuery query);
        分页的分页插件会帮我们做,制作高级查询
    -->

    <select id="loadPageList" resultType="TenantType">
        select * from t_tenant_type
        <include refid="whereSql"></include>
    </select>

keyword是mybatisPlus封装好的
不知道是要获取keyword参数还是获取query里面keyword
1)如果是普通参数直接获取值
2)如果是对象参数,要获取里面的属性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值