[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
一、为什么要把包分开
一开始的时候,我也一直以为包连在一起和分开没什么区别,直到今天遇到了一个问题,在写mybatis的配置文件时,采用包扫描扫描不到文件,此时报错了。
经过我细心的研究发现,配置文件中的路径是用 / 区分,而包连在一起是用 . 连接的,所以路径不对。
一开始我还以为这种方式是idea独特的处理方法,也没想太多。但实际上, . 和 / 是有区别的,
具体体现在你写路径的时候,尤其是在maven项目中,写配置时会发现程序找不到文件,找了半天错也找不出来,因为压根就不知道这个会有影响。在写配置文件时,采用包扫描的方式会报错,因为尽管mapper.xml和接口文件在同一个包中,但编译到target文件夹时,这两个文件会分道扬镳,一个在com.xxx/mapper中,一个在com/xxx/mapper包中。
二、建包时如何把包自动分开
1.分开前的样子:
2.自动分层方法为:点击图片上的齿轮按钮 ,然后在选项中选择Compact Middle Packages
3.分开后的样子:
三、如何编写配置文件路径?
一开始我是用.来表示上下级关系的,但这样很快就会发现哪里不对。我们会发现路径不对,用.和用/是两回事,表示路径的正确方法应该是com/itbaizhan/xxx/xxx/...,如:
创建路径时,上面是:com/itbaizhan/springbootmybatis/mapper/StudentMapper
下面是:com.itbaizhan.springbootmybatis.mapper.StudentMapper
写在最后:
一定要小心!一定要小心!一定要小心!很多小的细节可能半天也搞不出来。
记录生活点滴,与君分享!