@Select("SELECT max(id) FROM user")
int maxId();
如果有数据返回int数字,如果表里没数据,直接报异常了,该怎么写?
org.apache.ibatis.binding.BindingException: Mapper method 'com.xxxMapper.maxId attempted to return null from a method with a primitive return type (int).
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:102)
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
1.返回值改为Integer 然后在service中判断下 如果是null 就返回0
2.增加ifnull之类的数据库方法包裹下max