My 16 month old is testing this boundary. My best tip is to just not give it too much attention. I don’t react, even if it hurts. I say gentle hands with mommy and give her the chance to touch me nicely and I move on to something else and distract her. It’s tough!
Books! My son loves being read to so this issue with my son was resolved with 2 books - only one he really connected with - “Hands Are Not For Hitting” by Martine Agassi board book on Amazon. Not only did it show him what he can do with his hands in a simple way he can understand (the book is short & to the point) it also gives the parent multiple tips on what to say/do & once I implemented those regularly on top of reading the story a lot, he stopped! I’d say it took approx a month this way
I understand your pain. The only thing slightly working for us right now is saying "I'm not going to let you hit me, that's not nice" and just keep walking away. We offer him a pillow to hit instead. We tell him he can punch it and slam his head against it, and demonstrate and sometimes that just turns into giggles. Or if you're holding him and he hits, set him down and repeat the "I'm not going to hold you if you're going to hit me, it's not nice." Hang in there. It's a rough phase but I'm still hopeful he grows out of it soon.