spring-boot-api-project-seed icon indicating copy to clipboard operation
spring-boot-api-project-seed copied to clipboard

restcontroller 中findById 主键类型问题

Open robinloop opened this issue 6 years ago • 2 comments

rest controller中主键查询默认是Integer,但是model主键有可能是string byte long等类型,使用时会报类型转换错误 这种情况现在是怎么处理的? 生成代码后手动修改controller的id类型吗?

robinloop avatar Feb 01 '19 07:02 robinloop

自定义Mapper 不继承 IdsMapper

a173030685 avatar Feb 12 '19 05:02 a173030685

自定义Mapper 不继承 IdsMapper

不是IdsMapper的问题,IdsMapper只有查询多个id和删除多个id的接口,并没有findById 将Service接口的findById参数修改为Object类型(现在是Integer类型),这样可以适配不同类型主键 但是controller层detail方法的参数必须指定参数类型,否则后续会报错,这里是否只能手动修改?

另外,如果使用自定义Mapper的话面临同样的手动修改问题

robinloop avatar Feb 12 '19 07:02 robinloop