Although leadership is considered a key factor in affecting employees' knowledge sharing behavior (KSB), previous literature has mainly focused on the direct relationship between it and KSB, neglecting the mediators and moderators in this relationship. To address this issue, this study explores when and how leader-member exchange (LMX) promotes KSB by examining affective commitment (AC) as mediator and employee general self-efficacy (GSE) and internal locus of control (ILOC) as boundary conditions. In addition, although these two positive self-view variables (i.e., GSE and ILOC) both exhibit positive effects on various work-related outcomes, based on self-verification theory, we posit that they may exhibit different moderating effects in the LMX-AC-KSB relationship. We empirically validated this moderated mediated model using data collected from 231 supervisor-subordinate pairs from an information technology company in China. The results show that GSE amplifies the mediated relationship between LXM and KSB via AC, but ILOC weakens this mediated relationship. Our study elucidates when and how LMX can effectively facilitate KSB and sheds new and nuanced light on the conceptual distinction between GSE and ILOC. The results of this study might direct managers how to develop relationships with their subordinates and how to maximally facilitate subordinates' KSB.