用SSM实现图书管理系统的图书类型管理模块用代码写出

时间: 2023-12-14 21:37:44 浏览: 29
以下是使用SSM框架实现图书管理系统的图书类型管理模块的代码示例: 1. 对应的Mapper接口:BookTypeMapper.java ```java package com.example.demo.mapper; import com.example.demo.pojo.BookType; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; @Mapper public interface BookTypeMapper { int insert(BookType record); int insertSelective(BookType record); int updateByPrimaryKeySelective(BookType record); int updateByPrimaryKey(BookType record); int deleteByPrimaryKey(Integer id); List<BookType> selectAllBookTypes(); BookType selectByPrimaryKey(Integer id); List<BookType> selectBookTypesByKeyword(@Param("keyword") String keyword); } ``` 2. 对应的Service接口:BookTypeService.java ```java package com.example.demo.service; import com.example.demo.pojo.BookType; import java.util.List; public interface BookTypeService { int addBookType(BookType bookType); int updateBookType(BookType bookType); int deleteBookType(Integer id); List<BookType> getAllBookTypes(); BookType getBookTypeById(Integer id); List<BookType> getBookTypesByKeyword(String keyword); } ``` 3. 对应的Service实现类:BookTypeServiceImpl.java ```java package com.example.demo.service.impl; import com.example.demo.mapper.BookTypeMapper; import com.example.demo.pojo.BookType; import com.example.demo.service.BookTypeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class BookTypeServiceImpl implements BookTypeService { @Autowired private BookTypeMapper bookTypeMapper; @Override public int addBookType(BookType bookType) { return bookTypeMapper.insertSelective(bookType); } @Override public int updateBookType(BookType bookType) { return bookTypeMapper.updateByPrimaryKeySelective(bookType); } @Override public int deleteBookType(Integer id) { return bookTypeMapper.deleteByPrimaryKey(id); } @Override public List<BookType> getAllBookTypes() { return bookTypeMapper.selectAllBookTypes(); } @Override public BookType getBookTypeById(Integer id) { return bookTypeMapper.selectByPrimaryKey(id); } @Override public List<BookType> getBookTypesByKeyword(String keyword) { return bookTypeMapper.selectBookTypesByKeyword(keyword); } } ``` 4. 对应的Controller类:BookTypeController.java ```java package com.example.demo.controller; import com.example.demo.pojo.BookType; import com.example.demo.service.BookTypeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.List; @Controller @RequestMapping("/bookType") public class BookTypeController { @Autowired private BookTypeService bookTypeService; @GetMapping("/list") public String list(Model model) { List<BookType> bookTypes = bookTypeService.getAllBookTypes(); model.addAttribute("bookTypes", bookTypes); return "bookType/list"; } @GetMapping("/add") public String add(Model model) { model.addAttribute("bookType", new BookType()); return "bookType/add"; } @PostMapping("/add") public String add(BookType bookType) { bookTypeService.addBookType(bookType); return "redirect:/bookType/list"; } @GetMapping("/update/{id}") public String update(@PathVariable("id") Integer id, Model model) { BookType bookType = bookTypeService.getBookTypeById(id); model.addAttribute("bookType", bookType); return "bookType/update"; } @PostMapping("/update") public String update(BookType bookType) { bookTypeService.updateBookType(bookType); return "redirect:/bookType/list"; } @GetMapping("/delete/{id}") public String delete(@PathVariable("id") Integer id) { bookTypeService.deleteBookType(id); return "redirect:/bookType/list"; } @GetMapping("/search") public String search(@RequestParam(value = "keyword", required = false) String keyword, Model model) { List<BookType> bookTypes; if (keyword == null || keyword.equals("")) { bookTypes = bookTypeService.getAllBookTypes(); } else { bookTypes = bookTypeService.getBookTypesByKeyword(keyword); } model.addAttribute("bookTypes", bookTypes); return "bookType/list"; } } ``` 5. 对应的页面文件:list.html、add.html、update.html list.html: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>图书类型管理</title> </head> <body> <h1>图书类型管理</h1> <a href="/bookType/add">添加图书类型</a> <form action="/bookType/search" method="get"> <input type="text" name="keyword" placeholder="请输入关键字"> <button type="submit">搜索</button> </form> <table border="1"> <tr> <th>编号</th> <th>名称</th> <th>描述</th> <th>操作</th> </tr> <tr th:each="bookType : ${bookTypes}"> <td th:text="${bookType.id}"></td> <td th:text="${bookType.name}"></td> <td th:text="${bookType.description}"></td> <td> <a th:href="@{/bookType/update/{id}(id=${bookType.id})}">修改</a> <a th:href="@{/bookType/delete/{id}(id=${bookType.id})}" onclick="return confirm('确认删除?')">删除</a> </td> </tr> </table> </body> </html> ``` add.html: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>添加图书类型</title> </head> <body> <h1>添加图书类型</h1> <form action="/bookType/add" method="post"> <label for="name">名称:</label> <input type="text" id="name" name="name" required> <br> <label for="description">描述:</label> <textarea id="description" name="description"></textarea> <br> <button type="submit">提交</button> </form> <a href="/bookType/list">返回列表</a> </body> </html> ``` update.html: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>修改图书类型</title> </head> <body> <h1>修改图书类型</h1> <form action="/bookType/update" method="post"> <input type="hidden" name="id" th:value="${bookType.id}"> <label for="name">名称:</label> <input type="text" id="name" name="name" th:value="${bookType.name}" required> <br> <label for="description">描述:</label> <textarea id="description" name="description" th:text="${bookType.description}"></textarea> <br> <button type="submit">提交</button> </form> <a href="/bookType/list">返回列表</a> </body> </html> ```

相关推荐

最新推荐

recommend-type

基于Vue实现图书管理功能

主要为大家详细介绍了基于Vue实现图书管理功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

基于SSM的会议管理系统毕业设计

基于SSM框架的会议管理系统系统,用户表。会议表,会议室表 用到的技术和实现的功能:存储过程用于数据实时变化,Ajax同步和异步技术,邮件发送功能需要的技术,用户登录权限,过滤器(非登录用户不可访问),eharts...
recommend-type

HP-Socket编译-Linux

HP-Socket编译-Linux
recommend-type

JavaScript_生活在Discord上的开源社区列表.zip

JavaScript
recommend-type

JavaScript_MultiOn API.zip

JavaScript
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

可见光定位LED及其供电硬件具体型号,广角镜头和探测器,实验设计具体流程步骤,

1. 可见光定位LED型号:一般可使用5mm或3mm的普通白色LED,也可以选择专门用于定位的LED,例如OSRAM公司的SFH 4715AS或Vishay公司的VLMU3500-385-120。 2. 供电硬件型号:可以使用常见的直流电源供电,也可以选择专门的LED驱动器,例如Meanwell公司的ELG-75-C或ELG-150-C系列。 3. 广角镜头和探测器型号:一般可采用广角透镜和CMOS摄像头或光电二极管探测器,例如Omron公司的B5W-LA或Murata公司的IRS-B210ST01。 4. 实验设计流程步骤: 1)确定实验目的和研究对象,例如车辆或机器人的定位和导航。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。