查询相关问题
if (nicheContractIds.size() > 0) {
String stringContractIds = nicheContractIds.stream().map(String::valueOf).collect(Collectors.joining(","));
// 使用自定义的sql
contractsQuery.addCustomWhere("id not in(" + stringContractIds +") ");//最终格式:id not in(12321323,2343242,53535)
}
SimpleDateFormat dateFormat = new SimpleDateFormat("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<Object> ratios = new ArrayList<>();
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);
}
错误写法
@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);