<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>诗人信息</title>
</head>
<link rel="stylesheet" href="element-ui/index.css">
<script src="./js/vue.js"></script>
<script src="./element-ui/index.js"></script>
<script src="./js/axios-0.18.0.js"></script>
<body>
<h1 align="center">诗人信息列表展示</h1>
<div id="app">
<el-table :data="rawTableData" style="width: 100%" stripe border >
<el-table-column type="index" label="编号" align="center" min-width="20%"></el-table-column>
<el-table-column prop="name" label="姓名" align="center" min-width="20%"></el-table-column>
<el-table-column prop="gender" label="性别" align="center" min-width="20%"></el-table-column>
<el-table-column prop="dynasty" label="朝代" align="center" min-width="20%"></el-table-column>
<el-table-column prop="title" label="头衔" align="center" min-width="20%"></el-table-column>
<el-table-column prop="style" label="风格" align="center" min-width="20%"></el-table-column>
</el-table>
</div>
</body>
<style>
.el-table .warning-row {
background: oldlace;
}
.el-table .success-row {
background: #f0f9eb;
}
</style>
<script>
new Vue({
el: "#app",
data() {
return {
rawTableData: []
}
},
mounted(){
axios.get('/listPoet').then(res=>{
if(res.data.code){
this.rawTableData = res.data.data;
}
});
},
methods: {
}
});
</script>
</html>
@RestController
public class PoetController{
@RequestMapping("/listPoet")
public Result list(){
// 1.加载并解析
String file= this.getClass().getClassLoader().getResource("poet.xml").getFile();
System.out.println(file);
List<Poet> poetList = XmlParserUtils2.parse(file, Poet.class);
//2.对数据进行转换处理
poetList.stream().forEach(poet -> {
//对性别处理
String gender = poet.getGender();
if ("1".equals(gender)){
poet.setGender("男");
}else if ("2".equals(gender)){
poet.setGender("女");
}
});
return Result.success(poetList);
}
}
package com.wust.dao.impl;
import com.wust.dao.PoetDao;
import com.wust.pojo.Poet;
import com.wust.utils.XmlParserUtils2;
import java.util.List;
public class PoetDaoA implements PoetDao {
@Override
public List<Poet> listPoet() {
String file= this.getClass().getClassLoader().getResource("poet.xml").getFile();
System.out.println(file);
List<Poet> poetList = XmlParserUtils2.parse(file, Poet.class);
return poetList;
}
}
package com.wust.controller;
import com.wust.pojo.Poet;
import com.wust.pojo.Result;
import com.wust.service.PoetService;
import com.wust.service.impl.PoetServiceA;
import com.wust.utils.XmlParserUtils2;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class PoetController2 {
private PoetService poetService =new PoetServiceA();
@RequestMapping("/listPoet")
public Result list(){
//调用Service获取数据
List<Poet> poetList = poetService.listPoet();
return Result.success(poetList);
}
}