springmvc java物件轉json
阿新 • • 發佈:2019-06-19
package com.atguigu.my.controller; import java.util.Collection; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.atguigu.my.bean.Employee; import com.atguigu.my.dao.EmployeeDao; @Controller public class JsonController { @Autowired private EmployeeDao employeeDao; @RequestMapping(value = "/testJson") @ResponseBody public Collection<Employee> getAll() { Collection<Employee> emps = employeeDao.getAll(); ; return emps; } }
只是寫一個<a href = "testJson">測試json</a>
然後再springmvc.xml中開啟註解驅動<mvc:annotation-driven/>
然後需要印如jackson的三個jar包,jackson是阿里巴巴產品,能夠自動將java