Student后台管理系统查询接口

实体类student代码

复制代码
package org.example.studentback01.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

@Data
@TableName("student")
public class Student {
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String no;
    private String name;
    private String password;
    private int sex;
    private int roleId;
    private String phone;
    @TableField(exist = false)
    private String isValid;

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", no='" + no + '\'' +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", sex=" + sex +
                ", roleId=" + roleId +
                ", phone='" + phone + '\'' +
                ", isValid='" + isValid + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public int getRoleId() {
        return roleId;
    }

    public void setRoleId(int roleId) {
        this.roleId = roleId;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getIsValid() {
        return isValid;
    }

    public void setIsValid(String isValid) {
        this.isValid = isValid;
    }
}

controller代码

复制代码
package org.example.studentback01.controller;

import org.example.studentback01.entity.Student;
import org.example.studentback01.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class helloController {
    @GetMapping
    public String hello(){
        return "hello world";
    }
    @Autowired
    private StudentService studentService;
    @GetMapping("/list")
    public List<Student> list(){
        return studentService.listAllStudent();
    }
}

StudentMapper

复制代码
package org.example.studentback01.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.example.studentback01.entity.Student;

import java.util.List;
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
     List<Student> listAllStudent();
}

StudentService

复制代码
package org.example.studentback01.service;

import com.baomidou.mybatisplus.extension.service.IService;
import org.example.studentback01.entity.Student;

import java.util.List;

public interface StudentService extends IService<Student> {
    List<Student> listAllStudent();


}

StudentServiceImpl

复制代码
package org.example.studentback01.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.studentback01.entity.Student;
import org.example.studentback01.mapper.StudentMapper;
import org.example.studentback01.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Resource
    private StudentMapper studentMapper;



    @Override
    public List<Student> listAllStudent() {
        return list();
    }
}

StudentMapper.xml

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org..example.studentback01.mapper.StudentMapper">
    <select id="listAllStudent" resultType="org.example.studentback01.entity.Student">
        select * from student
    </select>


</mapper>

数据库学生表结构

复制代码
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student`  (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '主键',
  `no` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '账号',
  `name` varchar(100) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '名字',
  `PASSWORD` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL COMMENT '密码',
  `age` int NULL DEFAULT NULL,
  `sex` int NULL DEFAULT NULL COMMENT '性别',
  `phone` varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT NULL COMMENT '电话',
  `role_id` int NULL DEFAULT NULL COMMENT '角色 0超级管理员,1管理员,2普通账号',
  `isValid` varchar(4) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL DEFAULT 'Y' COMMENT '是否有效,Y有效,其他无效',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;
相关推荐
寻星探路17 小时前
数据结构从青铜到王者第二十二话---反射
java·开发语言
要开心吖ZSH17 小时前
软件设计师备考-(十四)数据库设计
java·数据库·软考·软件设计师
xrkhy17 小时前
阿里云对象存储OSS的使用
java·数据库·阿里云
华仔啊17 小时前
刚学 Java 就被内存溢出劝退?这 10 个集合内存管理技巧救了我!
java·后端
老马啸西风17 小时前
敏感词性能提升14倍优化全过程 v0.29.0
java
Cloud-Future17 小时前
Spring MVC 处理请求的流程
java·spring·mvc
小扳17 小时前
SpringBootWeb 篇-深入了解 ThreadLocal 存在内存泄漏问题
java·开发语言·spring boot·面试
lxsy17 小时前
spring-ai-alibaba-deepresearch 学习(十三)——ResearcherNode
java·源码分析·deepresearch·ai-alibaba
ShineWinsu18 小时前
对于单链表相关经典算法题:206. 反转链表及876. 链表的中间结点的解析
java·c语言·数据结构·学习·算法·链表·力扣