It was constantly saying off and turning our backs on her and eventually she got the hang of it. I must say it did take a long time.
I'll say what takes somewhat less time, though you need buy-in from everyone in the house and the occasional guest at first.
Also know that some people might not like doing it this way, but I needed an immediate fix after my wife's beagle broke the skin of her 88 year old grandmother. There's nothing like seeing that kind of thing happen to get buy-in from someone. When they think about not following the plan and letting the dog jump and get petted, a simple "What about your grandma?" goes a long way.
When you open the door and you know they are going to come barreling into you, just lift your knee. The dog will jump and hit the knee and bounce off. At the same time, use the command, "off." But that isn't what the dog wants, it wants to be in your lap. At that point you can do the ignoring thing that other people have posted with.
This worked really well with my Brittany and now when we visit people, he just gets excited and rubs up against their legs to get petted. He's so good looking he always gets petted. I suppose I could train him to wait patiently, but I don't mind the rubbing, and others generally don't either. It is a lot different than jumping.
This training was over a year ago and I haven't had to do it since with my dogs, though if a friends' dog (70 pound lab) or a relatives dog (90 pound lab) comes at me when I open the door, I use it on them. If they can't train their dog not to jump on people, I won't let it jump on me. In fact, with the relatives dog, they alway remark how better behaved their dog is when I'm there because after our initial greeting, it just wants to lay at my feet.
Another friend's puppy tried jumping on me when I went to let it out for him and we did the same steps. The next day I went to let the dog out again and he didn't jump at all, just waited patiently for me to poor his food.
That is the proper time to show affection, when the dog is waiting patiently, doing exactly as you want it.