開發的過程中往往依賴的表過多直接按Map來傳遞數值,某些場景需要把Map轉換為實體類,這里貼一個最簡潔的方法,依賴阿里的FastJSon。
maven引入
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.54</version> </dependency>
類引入
import com.alibaba.fastjson.JSON;
轉換方法
Student entity = JSON.parseObject(JSON.toJSONString(map), Student.class);