《javaee 企业级应用开发》c卷

更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
实现一个学生信息管理系统,使用Spring Boot整合Spring Data JPA完成对学生数据的增删改查操作。请补全以下代码片段中的空缺部分(每空2分,一共12个空,共24分): ①配置依赖 <!-- data jpa 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>(1)____________________</artifactId> </dependency> ... ②设置配置信息 spring: datasource: url: "jdbc:mysql://localhost:3306/springbootdata?characterEncoding=utf-8&serverTimezone=Asia/Shanghai" username: root password: root jpa: show-sql: (2)______________# 控制台开启 SQL 显示 hibernate: ddl-auto: (3)______________# schema 更新策略... ③创建实体类 (4)______________// 实体注解 (5)______________(name = "student") // 指定当前实体对应的数据表名称 public class Student { @Id // 指定主键生成策略为数据库自动生成 @GeneratedValue(strategy = GenerationType.(6)______________) private Integer id; // 学生编号 private String name; // 学生姓名 private Integer age; // 年龄 private String major; // 专业 private String status; // 学籍状态(如“在读”、“毕业”) // setter/getter, toString() 方法省略}... ④自定义 Repository 接口 (7)______________// 标注接口 public interface StudentRepository extends JpaRepository<Student, Integer> { Student findByMajorAndStatus(String major, String status); @Modifying @Transactional @Query("delete from Student s where (8)______________") // 删除条件 List<Student> deleteStudentById((9)______("id") Integer id);... ⑤创建数据库 根据student实体类创建对应的数据库和数据表,并插入对应的测试数据。 ⑥创建项目启动类 (10)______________// 核心启动类 public class StudentApplication { public static void main(String[] args) { // 运行 SpringApplication.(11)______(StudentApplication.class, args); }... ⑦创建测试类 @SpringBootTest class StudentApplicationTests { @Autowired private StudentRepository studentRepository; @Test void saveStudent() { Student student = new Student(null, "王五", 21, "物联网工程", "在读"); studentRepository.(12)______________(student); // 新增学生 // 输出所有学生信息(可选方法) List<Student> all = studentRepository.findAll(); all.forEach(System.out::println); }...