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

springboot基础-demo

1.创建学生信息表

create table stu(id int unsigned primary key auto_increment comment 'ID',name varchar(100) comment '姓名',age tinyint unsigned comment '年龄',gender tinyint unsigned comment '性别, 1:男, 2:女',score double(5,2) comment '成绩',phone varchar(11) comment '手机号'
)comment '学生表';
ALTER TABLE stu CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
insert into stu(id, name, age, gender,score, phone) VALUES (null,'张三',18,'1',560,'18800000000');
insert into stu(id, name, age, gender,score, phone) VALUES (null,'李四',19,'1',572,'18800000001');
insert into stu(id, name, age, gender,score, phone) VALUES (null,'王五',20,'1',480,'18800000002');
insert into stu(id, name, age, gender,score, phone) VALUES (null,'赵六',18,'2',621,'18800000003');
insert into stu(id, name, age, gender,score, phone) VALUES (null,'黄七',17,'2',211,'18800000004');
insert into stu(id, name, age, gender,score, phone) VALUES (null,'孙八',18,'1',492,'18800000005');

2.创建项目工程

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

2.appliction.yml

spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatisusername: rootpassword: 1234

3.StuController

package com.itdanb.springboottest.controller;import com.itdanb.springboottest.pojo.Stu;
import com.itdanb.springboottest.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class StuController {@Autowiredprivate StuService stuService;@RequestMapping("/findById")public Stu findById(Integer id){return stuService.findById(id);}
}

Stumapper

package com.itdanb.springboottest.mapper;import com.itdanb.springboottest.pojo.Stu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;@Mapper
public interface StuMapper {@Select("select * from stu where id = #{id}")public Stu findById(Integer id);}

Stu

package com.itdanb.springboottest.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@AllArgsConstructor
@NoArgsConstructor
public class Stu {private Integer id;private String name;private Integer age;private Short gender;private String score;private String phone;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 Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public Short getGender() {return gender;}public void setGender(Short gender) {this.gender = gender;}public String getScore() {return score;}public void setScore(String score) {this.score = score;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}@Overridepublic String toString() {return "Stu{" +"id=" + id +", name='" + name + '\'' +", age=" + age +", gender=" + gender +", score='" + score + '\'' +", phone='" + phone + '\'' +'}';}
}

StuService

package com.itdanb.springboottest.service;import com.itdanb.springboottest.pojo.Stu;public interface StuService {public Stu findById(Integer id);
}

StuServiceImpl

package com.itdanb.springboottest.service.impl;import com.itdanb.springboottest.pojo.Stu;
import com.itdanb.springboottest.mapper.StuMapper;
import com.itdanb.springboottest.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class StuServiceImpl implements StuService {@Autowiredprivate StuMapper stuMapper;@Overridepublic Stu findById(Integer id) {return  stuMapper.findById(id);}
}

在这里插入图片描述

http://www.lryc.cn/news/593374.html

相关文章:

  • 【iOS】ZARA仿写
  • linux板远程操控——todesk
  • Matplotlib和Plotly知识点(Dash+Plotly分页展示)
  • Typecho博客评论无限滚动加载实现指南
  • windows wsl ubuntu 如何安装 maven
  • 算法题(175):小明的游戏
  • Github Actions Workflows 上传 Dropbox
  • Visual Studio Code(VSCode)中设置中文界面
  • 11.1Redis高可用集群部署
  • Elastic Search 8.x 分片和常见性能优化
  • PHP 就业核心技能速查手册
  • windows docker-01-desktop install windows10 + wls2 启用
  • LangGraph教程6:LangGraph工作流人机交互
  • 博图SCL语言中常用运算符使用详解及实战案例(下)
  • LangGraph教程10:LangGraph ReAct应用
  • Python Pandas读取Excel表格中数据并根据时间字段筛选数据
  • 月舟科技近调记录
  • 网络爬虫概念初解
  • ndexedDB 与 LocalStorage:全面对比分析
  • C++数据结构————集合
  • 【Keil5-map文件】
  • 阿里云服务器 CentOS 7 安装 MySQL 8.4 超详细指南
  • c#泛型集合(ArrayList和List、Dictionary的对比)
  • 每日面试题09:进程、线程、协程的区别
  • 48Days-Day03 | 删除公共字符,两个链表的第一个公共结点,mari和shiny
  • 【每日算法】专题十五_BFS 解决 FloodFill 算法
  • HD Video Converter Factory pro 高清视频转换器 v27.7.0 绿色中文便携版
  • 【2025最新】 .NET FrameWork微软离线运行库合集,一键安装版
  • Spring之【AnnotatedBeanDefinitionReader】
  • 前端面试专栏-工程化:28.团队协作与版本控制(Git)