分享一个前几天卡了我很久的问题
解决办法:
1.传输的数据用data:JSON.stringify(str),
微信小程序默认header为 header: { ‘Content-Type’: ‘application/json’ }
改成header: { ‘Content-Type’: ‘application/x-www-form-urlencoded;charset:utf-8’}
2.虽然在header中想把传输的数据编码从url改成utf-8,但是到后台中打印str发现还是url格式,所以转换格式并去掉多余字符
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@PostMapping("/wxGoodsQuery")
public List<Goods> goodsQuery(@RequestBody String str){
try{
str = URLDecoder.decode(str, "Utf-8");
str = str.replace("=","");
str = str.replaceAll("\"", "");
}catch (UnsupportedEncodingException e){
}
//System.out.println(str);
List<Goods> list = goodsService.queryGoodsByName("%"+str+"%");
list = list.stream().filter(goods -> goods.getGoodsStatus().equals(0)).collect(Collectors.toList());
return list;
}