PROFESSIONS:

Profession:0 = Farmer 
Profession:1 = Librarian
Profession:2 = Priest
Profession:3 = Blacksmith
Profession:4 = Butcher
Profession:5 = Generic

/summon Villager ~ ~ ~{Profession:#}




NAMING:

If you want to name your villager trades or add some extra character to your merchants, you can always give your villager a name.

Note that the "CustomNameVisable" tag - if set to true (1), will display the name even if your cursor isn't pointed at the villager.

It is set to false (0) by default, so if you want more of a speak-only-when-spoken-to sort of shop keeper, you can omit this tag.

Basic format is as follows:

/summon Villager ~ ~ ~ {CustomName:(the name you want),CustomNameVisable:1}




MAKING TRADES:

Once you've got a profession chosen, you can set up some reasonable trades to suit your situation. With this method, you can create markets on servers, add a 
fetch-quest element to your adventure map, and much more!

Note that the "buyB" tag is used to set the item for the second offer slot. If you don't want an item in the second slot, you can omit the tag.

Note also that the "Count" and "Damage' tags can be omitted if the items traded do not require them. Note also that the "maxUses" tag is the number of times
that a certain trade can be made. Every time the trade is conducted, it counts down to one. When maxUses reaches zero, the trade is removed.

Basic format is as follows:

/summon Villager ~ ~ ~ {Offers:Recipes:[{maxUses:#,buy:{id:#,Count:#,Damage:#},buyB:{id:#,Count:#,Damage:#},sell:{{id:#,Count:#,Damage:#}}}]}

/summon Villager ~ ~ ~ {Offers:Recipes:[{maxUses:9,buy:{id:comand_block,Count:3},sell:{{id:emerald,Count:3}}}]}


PREVENTING FUTHER TRADES:

If you don't want more trades to generate randomly when you make a successful trade with your fancy new custom villager, you can add an impossible trade at the
end of your trade list. I use ID:118, a cauldron technical block, because it conveys a nice sense of emptiness. I name it "No More Trades" to further drive the
point home, and so the trade doesn't say "Cauldron" when you hover over it.

Basic format is as follows:

/summon ~ ~ ~ {Offers:{Pecipes:[{maxUses:#,buy:{id:#},sell:{id:#}},{maxUses:1,buy:{id:118,tag:{display:{Name:No More Trades}}}}]}}




PUT IT ALL TOGETHER:

So to put together everything we've learned, the full command template would look like this:

/summon Villager ~ ~ ~ {CustomName:(the name you want),Profession:#,Offers:{Pecipes:[{maxUses:#,buy:{id:#,Count:#,Damage:#},sell:{id:#,Count:#,Damage:#}},{maxUses:1,buy:{id:118,tag:{display:{Name:No More Trades}}},sell:{id:118,tag:{display:{Name:No More Trades}}}}]}}