For a while, it really bothered me when my son would hit me -- especially in front of other people. I knew that it bothered me more because I was hurt and offended that I do so much for him, I'm literally doing a song and dance to help him through the diaper change, and he repays me by hitting me.
But then I made a decision. I decided that it was something he was doing for other reasons, those which I simply don't understand completely. His perspective is different from mine, his ability to express himself and to control his life is different from mine, and he wasn't trying to tell me that he didn't appreciate me, he just didn't know what else to do, I guess.
Other techniques: As you mentioned, prevention is helpful. Along hte lines of making more behavior acceptable ... I also try to warn him about things he won't like, to give him time to get used to the idea. We also compromise on some things -- it makes the situation acceptable to both of us, gives him a sense of control, etc.
I used to try telling him it hurt mommy, and that didn't work for us at all. Then I happened to say once, when I saw him getting that look on his face during a diaper change, "Do you want to hit Mommy?" And, weirdly, that stops it -- it's like it makes it a conscious decision for him rather than an immediate physical expression of frustration. I don't always remember to say it, though. Anyway, after I say it, he usually lowers his hand, whimpers, and comes in for a hug. I say something about how I know he's upset/frustrated/irritated because of XYZ, snuggle with him, and that's that.
Also, he once expressed a desire to hit me shortly after playing knock-knock with his daddy. (I wouldn't assist him in doing something unsafe, which frustrated him.) In the process of getting ready to hit me, he got distracted, I guess, and knocked on a wooden furniture item. A friend of mine had been trying to teach her daughter to hit inanimate objects instead of humans, so that came to mind and I said, almost jokingly (though he's too young to understand that), "That's an interesting idea -- to hit something else instead when you feel like hitting Mommy." For some time thereafter, when the urge to hit me would strike, he would knock on the wall (or whatever was nearby), then present his hand to me for a kiss for his owee. I felt so bad every single time that happened! It was so sweet of him.
Occasionally, I'll catch his hand as it comes up to my face, and then he goes straight to the post-upset hug, poor thing. I feel so bad for him -- all that frustration, no way for him to control preventing it, and no other way to express it.
Ultimately, though, what's worked for me is to change ME, not him. I decided I couldn't change him. He knows that I don't like being hit, and he always seems to regret hitting me (he comes in for a hug afterwards -- no surprise. It's like making up after a fight.), and one day this phase will pass. In the meantime, it doesn't usually hurt me physically, and I've made up my mind not to let it upset me emotionally, so it just doesn't happen much and just doesn't bother me much.
Long post, so I'll end there. Good luck.