当前位置: 首页 > article >正文

springboot实现查询学生

文章目录

  • 数据库
  • 前端 请求
  • mybatis

数据库

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

前端 请求

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<a href="/list">启动学生管理系统</a>
</body>
</html>

mybatis

package com.example.demo.mapper;import com.example.demo.po.StudentPO;
import org.apache.ibatis.annotations.Select;import java.util.List;public interface StudentMapper {@Select("select * from student")List<StudentPO> selectStudentAll();}
package com.example.demo.po;import java.util.Objects;public class StudentPO {Integer id;String name;String stu_id;String major;@Overridepublic String toString() {return "StudentPO{" +"id=" + id +", name='" + name + '\'' +", stu_id='" + stu_id + '\'' +", major='" + major + '\'' +'}';}@Overridepublic boolean equals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;StudentPO studentPO = (StudentPO) o;return Objects.equals(id, studentPO.id) && Objects.equals(name, studentPO.name) && Objects.equals(stu_id, studentPO.stu_id) && Objects.equals(major, studentPO.major);}@Overridepublic int hashCode() {return Objects.hash(id, name, stu_id, major);}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getStu_id() {return stu_id;}public void setStu_id(String stu_id) {this.stu_id = stu_id;}public String getMajor() {return major;}public void setMajor(String major) {this.major = major;}public StudentPO(Integer id, String name, String stu_id, String major) {this.id = id;this.name = name;this.stu_id = stu_id;this.major = major;}public StudentPO() {}
}
package com.example.demo;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com/example/demo/mapper")
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}
package com.example.demo.controller;import com.example.demo.mapper.StudentMapper;
import com.example.demo.po.StudentPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;import java.rmi.MarshalledObject;@Controller
public class List {@AutowiredStudentMapper studentMapper;@RequestMapping("/list")public ModelAndView listStudent(){ModelAndView modelAndView = new ModelAndView();java.util.List<StudentPO> studentPOS = studentMapper.selectStudentAll();modelAndView.addObject("students",studentPOS);modelAndView.setViewName("list");return  modelAndView;}}

展示页面

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<h1>学生列表</h1><table border="1px"><tr><td>姓名</td><td>学号</td><td>专业</td></tr><tr th:each="stu:${students}"><td th:text="${stu.getName()}"></td><td th:text="${stu.getStu_id()}"></td><td th:text="${stu.getMajor()}"></td></tr>
</table></body>
</html>

在这里插入图片描述
在这里插入图片描述

spring.application.name=demo
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/yanyu
spring.datasource.username=root
spring.datasource.password=root
server.port=8081
#  默认  8080   ,更改  spring boot  项目 启动的端口号
http://www.lryc.cn/news/2402016.html

相关文章:

  • 深入解析C++五大常用设计模式:原理、实现与应用场景
  • 标识符Symbol和迭代器的实现
  • Appium+python自动化(九)- 定位元素工具
  • Unity 中实现可翻页的 PageView
  • clickhouse常用语句汇总——持续更新中
  • 云计算 Linux Rocky day05【rpm、yum、history、date、du、zip、ln】
  • LuaJIT2.1 和 Lua5.4.8 性能对比
  • 深度学习姿态估计实战:基于ONNX Runtime的YOLOv8 Pose部署全解析
  • 深度探索:如何用DeepSeek重构你的工作流
  • 深入解析与解决方案:处理Elasticsearch中all found copies are either stale or corrupt未分配分片问题
  • 【NLP 78、手搓Transformer模型结构】
  • yum更换阿里云的镜像源
  • 如何自定义WordPress主题(5个分步教程)
  • ios版本的Tiktok二次安装不上,提示:Unable to Install “TikTok”
  • react实现markdown文件预览
  • Neo4j 认证与授权:原理、技术与最佳实践深度解析
  • Android Studio 配置之gitignore
  • PDF处理控件Aspose.PDF教程:在 C# 中更改 PDF 页面大小
  • Perl One-liner 数据处理——基础语法篇【匠心】
  • PHP 打印扩展开发:从易联云到小鹅通的多驱动集成实践
  • rust或tauri项目执行命令的时候,cmd窗口也会弹出显示解决方法
  • [软件工程] 文档 | 技术文档撰写全流程指南
  • 使用Python进行函数作画
  • Python应用continue关键字初解
  • 微型导轨在手术机器人领域中有哪些关键操作?
  • FPGA 的硬件结构
  • EasyRTC音视频实时通话助力新一代WebP2P视频物联网应用解决方案
  • QT开发技术【ffmpeg + QAudioOutput】音乐播放器 完善
  • vscode 离线安装第三方库跳转库
  • DevExpress WinForms v24.2 - 新增日程组件、电子表格组件功能扩展