一、知识点整理
三层架构的含义
Controller: 控制层,接收前端发送的请求,对请求进行处理,并响应数据。
Service:业务逻辑层,处理具体的业务逻辑。
Dao(Data Access Object): 数据访问层(持久层),负责数据访问操作,包括数据的增、删、改、查。
二、代码实现
原EmpController.java文件中的代码:
package com.example.controller;
import com.example.pojo.Emp;
import com.example.pojo.Result;
import com.example.service.EmpService;
import com.example.service.impl.EmpServiceA;
import com.example.utils.XmlParserUtils;
import com.fasterxml.jackson.annotation.JsonTypeId;
import jdk.jshell.spi.ExecutionControl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class EmpController {
@RequestMapping("/listEmp")
public Result list(){
//1、加载并解析emp.xml
String file=this.getClass().getClassLoader().getResource("emp.xml").getFile();
System.out.println(file);
List<Emp> empList= XmlParserUtils.parse(file,Emp.class);
//2、对数据进行转换处理
empList.stream().forEach(emp->{
//book 1:十二钗正册,2:十二钗副册,3:十二钗又副册
String book=emp.getBook();
if("1".equals(book)){
emp.setBook("十二钗正册"