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;
相关推荐
天若有情6733 分钟前
Java Swing 实战:从零打造经典黄金矿工游戏
java·后端·游戏·黄金矿工·swin
lichong95131 分钟前
Android studio 修改包名
android·java·前端·ide·android studio·大前端·大前端++
lichong95133 分钟前
Git 检出到HEAD 再修改提交commit 会消失解决方案
java·前端·git·python·github·大前端·大前端++
@yanyu66635 分钟前
Tomcat安装与HTML响应实战
java·tomcat·html
呼哧呼哧.1 小时前
Spring的核心思想与注解
数据库·sql·spring
Chen-Edward2 小时前
有了Spring为什么还有要Spring Boot?
java·spring boot·spring
云创智城-yuncitys2 小时前
SpringCloud 架构在智慧交通路侧停车系统中的实践:从技术落地到城市级服务升级
spring·spring cloud·架构·智慧城市·停车系统·充电系统源码
陈小桔3 小时前
idea中重新加载所有maven项目失败,但maven compile成功
java·maven
小学鸡!3 小时前
Spring Boot实现日志链路追踪
java·spring boot·后端
xiaogg36783 小时前
阿里云k8s1.33部署yaml和dockerfile配置文件
java·linux·kubernetes