查询相关问题
if(nicheContractIds.size() > 0) {
String stringContractIds = nicheContractIds.stream().map(String::valueOf).collect(Collectors.joining(","));// 使用自定义的sqlcontractsQuery.addCustomWhere("id not in("+ stringContractIds +") ");//最终格式:id not in(12321323,2343242,53535)}
SimpleDateFormat dateFormat = newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");String createTime = dateFormat.format(nicheModel.getCreateTime());// createTime需要转换成2020-09-02 12:00:00格式,new Date()格式不正确contractsQuery.addGtWhere("createTime",createTime);
// 错误不支持contractsQuery.addNotInWhere("id",nicheContractIds);
// 正确使用Query query = Query.instance();List ratios = newArrayList<>();ratios.add(HUNDRED);ratios.add(ZERO);query.addEqWhere("customerId",customerId);query.addNotInWhere("ratio",ratios);query.addEqWhere("isOpen", false);query.addEqWhere("isDeleted", false);query.addNotEqWhere("followStatus",FollowStatusConstant.CLOSE);if(null!= nicheId) {
// 编辑时排除自己query.addNotEqWhere("id",nicheId);}
Method has too many Body parameters的处理办法
SpringCloudFeign报错:Method has too many Body parameters
1、feign多参数问题
1.1GET方式
错误写法
@RequestMapping(value="/test", method=RequestMethod.GET)
Model test(final String name, final int age);
启动服务的时候,会报如下异常:
Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.chhliu.springboot.restful.vo.User com.chhliu.springboot.restful.feignclient.UserFeignClient.findByUsername(java.lang.String,java.lang.String)
异常原因:当使用Feign时,如果发送的是get请求,那么需要在请求参数前加上@RequestParam注解修饰,Controller里面可以不加该注解修饰 ,@RequestParam可以修饰多个,@RequestParam是用来修饰参数,不能用来修饰整个对象。
注意:@RequestParam Content-Type 为 application/x-www-form-urlencoded 而这种是默认的
正确写法
@GetMapping("/getSchoolDetail")
public ResultMap getSchoolDetail(@RequestParam("kSchoolId") LongkSchoolId,
@RequestParam("kSchoolYearId") Long kSchoolYearId);
1.1POST方式
错误写法
public int save(@RequestBody final User u, @RequestBody final School s);
feign中你可以有多个@RequestParam,但只能有不超过一个@RequestBody,@RequestBody用来修饰对象,但是既有@RequestBody也有@RequestParam,那么参数就要放在请求的url中,@RequestBody修饰的就要放在提交对象中。
注意 用来处理@RequestBody Content-Type 为 application/json、application/xml编码的内容
正确写法
public int save(@RequestBody final Person p,@RequestParam("userId") String userId,@RequestParam("userTel") String userTel);
获取query对象数据
if(query.getWhere().containsKey("createTime")) {
Map createTime = (Map) query.getWhere().get("createTime");if(createTime.containsKey("$between")) {
Object between = createTime.get("$between");ArrayList list =(ArrayList)between;String startTime;String endTime;if(list.size() > 0) {
startTime = list.get(0);endTime = list.get(1);if(!startTime.equals(endTime)) {
SimpleDateFormat simpleDateFormat = newSimpleDateFormat("yyyy-MM-dd");Date parse = simpleDateFormat.parse(startTime);Date parse1 = simpleDateFormat.parse(endTime);parse = newDate();parse1 = newDate();}
}
}
}