McLaren's Lewis Hamilton has won his first race of the 2011 season after an entertaining Chinese Grand Prix in Shanghai.