Web第六次作业

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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值