1.显示诗人信息
2.自己编写一个数据库表格进行数据显示
编写对应的实体类Teacher
package com.itheima.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Teacher {
private String id;
private String name;
private Short age;
private Short gender;
private String phone;
}
编写对应的TeacherMapper类
package com.itheima.mapper;
import com.itheima.pojo.Teacher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface TeacherMapper {
@Select("select * from mybatis.teacher")
public List<Teacher> findall();
}
TeacherService接口及其实现类
package com.itheima.service;
import com.itheima.pojo.Teacher;
import java.util.List;
public interface TeacherService {
public List<Teacher> findallService();
}
package com.itheima.service.impl;
import com.itheima.mapper.TeacherMapper;
import com.itheima.pojo.Teacher;
import com.itheima.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TeacherServicelmpl implements TeacherService {
@Autowired
TeacherMapper teacherMapper;
@Override
public List<Teacher> findallService(){
return teacherMapper.findall();
}
}
编写对应的StudentController类
package com.itheima.controller;
import com.itheima.pojo.Teacher;
import com.itheima.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class TeacherController {
@Autowired
private TeacherService teacherService;
@RequestMapping("/teacher")
public List<Teacher> find1(){
return teacherService.findallService();
}
}
teacher.html代码
<!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>
<script src="./js/vue.js"></script>
<script src="./js/axios-0.18.0.js"></script>
<body>
<h1 align="center">教师信息列表展示</h1>
<div id="app" align="center">
<table border="1" cellspacing="0" width="60%">
<tr>
<th>序号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>电话</th>
<th>操作</th>
</tr>
<tr align="center" v-for="(teacher,index) in tableData">
<td>{{teacher.id}}</td>
<td>{{teacher.name}}</td>
<td>{{teacher.age}}</td>
<td>{{teacher.gender}}</td>
<td>{{teacher.phone}}</td>
<td class="text-center">修改 删除</td>
</tr>
</table>
</div>
</body>
<script>
new Vue({
el: "#app",
data() {
return {
tableData: []
}
},
mounted(){
axios.get('/teacher').then(res=>{
this.tableData = res.data;
});
},
});
</script>
</html>