案例:获取员工数据,返回统一响应结果,在页面渲染展示
package com.bignyi.controller;
import com.bignyi.pojo.Emp;
import com.bignyi.pojo.Result;
import com.bignyi.utils.XmlParserUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.naming.spi.DirStateFactory;
import java.util.List;
@RestController
public class EmpController {
@RequestMapping("/listEmp")
public Result list(){
String file = this.getClass().getClassLoader().getResource("emp.xml").getFile();
System.out.println(file);
List<Emp> empList = XmlParserUtils.parse(file, Emp.class);
empList.stream().forEach(emp -> {
String gender= emp.getGender();
if ("1".equals(gender)) {
emp.setGender("男");
} else if ("2".equals(gender)) {
emp.setGender("女");
}
String job = emp.getJob();
if ("1".equals(job)) {
emp.setJob("讲师");
} else if ("2".equals(job)) {
emp.setJob("教授");
}
});
return Result.success(empList);
}
}