List<?> is converted to List<entity class>

  • step:
    • 1. for loop traversallist<Object>
    • 2. Use the Object[] array to accept each Object object
    • 3. Take the parameters in Object[] and put them into the entity object
    • 4. Put the entity object into the list <entity class>
String sql = "SELECT * FROM department";
        List<?> list = baseDao.findBySql(sql, 0, 0, null);
        List<Department> departmentList = new ArrayList<Department>();
        for (int i = 0; i < list.size(); i++) {//Object---> Department
            Object[] obj = (Object[]) list.get(i);
            departmentList.add(new Department((Integer) obj[0], (String) obj[1]));
        }
        return departmentList;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326001878&siteId=291194637