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

浙江网站建设公司排名会计常用的三个软件

浙江网站建设公司排名,会计常用的三个软件,市场营销是做什么的,wordpress电商ar实战:实现学生信息管理模块 环境准备 JDKSpring BootMyBatis 创建Spring Boot项目 使用Spring Initializr创建一个新的Spring Boot项目,并添加以下依赖: Spring WebMyBatis FrameworkMySQL Driver 数据库设计 在MySQL数据库中创建一个名…

实战:实现学生信息管理模块

  1. 环境准备
  • JDK
  • Spring Boot
  • MyBatis
  1. 创建Spring Boot项目
    使用Spring Initializr创建一个新的Spring Boot项目,并添加以下依赖:
  • Spring Web
  • MyBatis Framework
  • MySQL Driver
  1. 数据库设计
    在MySQL数据库中创建一个名为studentdb的数据库,并创建一个名为students的表,表结构如下:
CREATE TABLE `students` (`id` int NOT NULL AUTO_INCREMENT,`name` varchar(255) NOT NULL,`email` varchar(255) NOT NULL,`address` varchar(255) NOT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  1. 配置数据源和MyBatis
    application.properties文件中添加以下配置:
# 数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/studentdb?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# MyBatis配置
mybatis.type-aliases-package=com.example.demo.entity
mybatis.mapper-locations=classpath:mapper/*.xml
  1. 定义实体类
    创建一个名为Student的实体类,代码如下:
public class Student {private int id;private String name;private String email;private String address;// getter和setter方法省略
}
  1. 定义Mapper接口
    创建一个名为StudentMapper的Mapper接口,代码如下:
@Mapper
public interface StudentMapper {List<Student> getAllStudents();Student getStudentById(int id);int addStudent(Student student);int updateStudent(Student student);int deleteStudent(int id);
}
  1. 定义Mapper XML配置文件
    resources/mapper下创建一个名为StudentMapper.xml的配置文件,代码如下:
<mapper namespace="com.example.demo.mapper.StudentMapper"><resultMap id="StudentMap" type="com.example.demo.entity.Student"><id property="id" column="id" /><result property="name" column="name" /><result property="email" column="email" /><result property="address" column="address" /></resultMap><select id="getAllStudents" resultMap="StudentMap">SELECT * FROM students</select><select id="getStudentById" resultMap="StudentMap">SELECT * FROM students WHERE id=#{id}</select><insert id="addStudent" parameterType="com.example.demo.entity.Student">INSERT INTO students(name, email, address) VALUES(#{name}, #{email}, #{address})</insert><update id="updateStudent" parameterType="com.example.demo.entity.Student">UPDATE students SET name=#{name}, email=#{email}, address=#{address} WHERE id=#{id}</update><delete id="deleteStudent">DELETE FROM students WHERE id=#{id}</delete>
</mapper>
  1. 实现Controller
    创建一个名为StudentController的Controller,代码如下:
@RestController
@RequestMapping("/api")
public class StudentController {@Autowiredprivate StudentMapper studentMapper;@GetMapping("/students")public List<Student> getAllStudents() {return studentMapper.getAllStudents();}@GetMapping("/students/{id}")public Student getStudentById(@PathVariable int id) {return studentMapper.getStudentById(id);}@PostMapping("/students")public int addStudent(@RequestBody Student student) {return studentMapper.addStudent(student);}@PutMapping("/students")public int updateStudent(@RequestBody Student student) {return studentMapper.updateStudent(student);}@DeleteMapping("/students/{id}")public int deleteStudent(@PathVariable int id) {return studentMapper.deleteStudent(id);}
}
  1. 测试API
    使用Postman或其他工具测试API,例如:
  • GET http://localhost:8080/api/students
  • GET http://localhost:8080/api/students/1
  • POST http://localhost:8080/api/students
    请求体:
    {"name": "张三","email": "zhangsan@example.com","address": "北京市海淀区"
    }
    
  • PUT http://localhost:8080/api/students
    请求体:
    {"id": 1,"name": "张三","email": "zhangsan@example.com","address": "北京市海淀区"
    }
    
  • DELETE http://localhost:8080/api/students/1

完成以上步骤后,就可以使用Spring Boot和MyBatis实现一个简单的学生信息管理模块了。

http://www.yayakq.cn/news/419569/

相关文章:

  • 注册网站会员违法.tel域名不可以做网站域名吗
  • 有关网站升级建设的申请书兴义网站开发公司
  • 郑州快速建站公司网站需要哪些费用
  • 做网站公司关键词简述企业网站的建设流程
  • wordpress 备份恢复郑州网站优化公司电话
  • 建设网站需要备案么wordpress链接打不开
  • 阜阳手机网站制作微信扫码下单小程序怎么做
  • 专门写文章的网站那些网站可以做公司的推广
  • 白沟17网站一起做网店机械 网站源码
  • vip影院自助建站系统关键词推广效果分析
  • 建站网址什么意思建筑网站搜图
  • 创业网站建设方案项目书视频类网站备案
  • 做旅游网站选什么空间互联网运营管理
  • 宁波网站seo诊断工具国家时事新闻2020最新
  • 做技术分享网站有哪些哪个装修公司比较好
  • 网站建设项目背景网站后台的网址忘记了
  • 游戏网站搭建需要多少钱哪里ui培训班好
  • 石家庄公司建站深圳平台网站建设
  • 网站名和域名能一样吗做车展的网站
  • 建设比较好网站互联网o2o是什么意思
  • 简单企业网站建设培训班线上优化
  • 合肥做网站专家做网站对于不同的分辨率
  • 高新区手机网站建设网站开发 零基础
  • 国际网站哪里做阜新网站制作
  • 广州市网站集约化建设工作要求怎么在wordpress建站
  • 制作一个网站平台要多钱怎么在百度上建立自己的网页
  • 国外公司做中国网站上海 企业
  • 潍城区建设局网站做网站需要ftp
  • 高端学校网站建设网站主题页
  • 长春seo公司长春网站设计gif动图素材网站