Java
参数名返回前端全小写问题
例子:
@Data
public class Test{
private Integer sCount;
private Integer uCount;
private Integer dCount;
private Integer iCount;
}
以上代码参数明明是sCount、uCount、dCount、iCount,但到前端收到的却是scount、ucount、dcount、icount,具体原因可以追踪以下spring返回对象时的参数封装过程,这里给出两个解决方案
解决方案
1、手写get、set方法
这里是因为lombok插件生成get、set方法问题,手写get、set方法即可解决
2、使用注解@JsonProperty()
@JsonProperty("sCount")、@JsonProperty("uCount")、@JsonProperty("dCount")、@JsonProperty("iCount")
Mybais小坑
通过pagehelper或者mybatis-plus的分页插件进行分页小坑
正常来说mybatis会先执行一次count,假如count没有值,则不会执行select
坑1:
当有左连接查询时,例如
select a.*,b.* from a left join b on a.id = b.aid
如果where条件中没有用到b,则count时会将left join b省略,只有用到b时,例如
select a.*,b.* from a left join b on a.id = b.aid where b.id = 1
count时才会用到b
坑2:
如果分页查询的pagesize是0,则即使count有值也不会执行select
坑三:
一个事务提交中,如果使用两次helper,第二个会保留第一个helper的属性,第二个使用之前先初始化一下helper