问题描述
我们有一个基于Spring-Boot 1.5.9的Spring Data Rest API,可从升级的(spring-boot 2.2.4)OpenFeign / Hateoas客户端调用。
自从升级客户端以来,由于在HTML中转义了多个Person实体字段中的“&”字符,因此我们在API中遇到了数据库约束异常。例如,
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(opt =>
{
opt.AddPolicy("CorsPolicy",c => c.AllowAnyOrigin()
.AllowAnyHeader()
.AllowCredentials()
.AllowAnyMethod());
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app,IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseCors("CorsPolicy");
}
app.UseAuthentication();
app.UseMvc(routes => routes.MapRoute(
"default","api/{controller}/{action}/{id?}"
));
}
}
通过
showQuickJumper={{ goButton: "Your text" }}
是否可以禁用此编码?
44TC&R&GG
解决方法
我能够通过将首选的http转换器设置为gson来解决此问题,该转换器具有禁用html转义的属性。
spring.http.converters.preferred-json-mapper=gson
spring.gson.disable-html-escaping=true