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;@Overridepublic 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 {@GetMappingpublic String hello(){return "hello world";}@Autowiredprivate 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 {@Resourceprivate StudentMapper studentMapper;@Overridepublic 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;