跨域
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)如果是对象参数,要获取里面的属性