I believe that racism (and sexism, and 'the victim is responsible for the crime occurring', and... and...) continues only if the society allows it to.
In other words, people who say/do racist (etc) things are aware of the response they get. If they get silence or approval, they'll continue. If they get disapproval, they know that their views aren't acceptable.
Yes, that's an oversimplification. For instance, someone who knows their views aren't acceptable often tries to make their views become acceptable. Some will do extreme things to get attention for their views.
In the case of a boyfriend/girlfriend or someone else who's close to you, the best thing to do might be to quietly take them aside and let them know it's hurtful to you when they do that.
I can't stand it when people intentionally try to 'get my goat'. To me, that's just another sort of bullying.
I understand that some people perceive it as 'just fun'. But if your boyfriend doesn't already know that that behaviour hurts some people, he probably needs to learn it.