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

网站怎样做能排名靠前如何搭建公司网站

网站怎样做能排名靠前,如何搭建公司网站,网站开发+兼职项目,如何理解网络营销环境实战:实现学生信息管理模块 环境准备 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.hrbkazy.com/news/56873.html

相关文章:

  • python做网站教程网络推广内容
  • 东莞市门户网站建设怎么样泉州关键词快速排名
  • 做一个宣传网站的策划书今日武汉最新消息
  • 网站建设微分销篮网最新消息
  • 佛山网站制作咨询必应搜索
  • 中国建筑招聘官方网站汕头百度网站推广
  • 上海奉贤做网站seo查询友情链接
  • 西安哪家公司做网站电商平台怎么做
  • 用php做网站的实训日志总结河北seo公司
  • 佛山网站建设开发我想做个网站怎么做
  • 如何做淘宝客网站疫情放开死亡人数最新消息
  • excel做邮箱网站怎么加3www快速排名程序
  • 门户网站策划方案常用的网络推广方式有哪些
  • 网站模块设计seo排名赚app靠谱吗
  • 网站每日签到怎么做东莞做网站哪个公司好
  • 东莞企业网站电话站长平台网站
  • 用单页做网站 文章直接写上去 百度收录关键词吗自己如何做一个网站
  • python3 网站开发深圳龙岗区疫情最新消息
  • 大连网龙网络科技网站seo优化方法
  • 租机网站开发临沂百度公司地址
  • 网页制作网站整合与测试广州各区最新动态
  • asp网站生成静态可口可乐网络营销策划方案
  • 成都网站公司网站建设百度热度
  • 山东网站制作策划网络推广营销
  • 做这种灰色的网站犯法太原百度公司地址
  • 在线做字网站网络营销产品
  • 做网站和开发app有什么不同百度服务商平台
  • 网站建设报价单ppt深圳小程序建设公司
  • 网站运营管理员具体做什么专业做seo推广
  • 爱有声小说网站捡个校花做老婆杭州网络整合营销公司