java工作中遇到难题_Java工作中遇到的问题

查询相关问题

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();}

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值