1.创建数据表及字段
CREATE TABLE hotel_room_type ( -- 房间类型ID,作为主键 room_type_id INT PRIMARY KEY AUTO_INCREMENT, -- 房间类型名称 room_type_name VARCHAR(50), -- 房间类型描述 room_type_description VARCHAR(50), -- 创建时间,默认为当前时间戳 create_time DATETIME DEFAULT CURRENT_TIMESTAMP );
2.搭建增删改查
到后台菜单管理新增一个房间类型管理
新建组件文件夹
将房间类型表导入
复制对应的domain,mapper,service,controller等测试功能不报错就行
3.完善增删改查
后端添加正则表达式
前端限制规则
后端完整代码
package com.rome.hotel.data.service.impl; import java.util.List; import com.rome.hotel.common.utils.DateUtils; import com.rome.hotel.data.domain.HotelUser; import com.rome.hotel.data.utils.RegexUtils; import io.jsonwebtoken.lang.Assert; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.rome.hotel.data.mapper.HotelRoomTypeMapper; import com.rome.hotel.data.domain.HotelRoomType; import com.rome.hotel.data.service.IHotelRoomTypeService; /** * 房间类型Service业务层处理 * * @author rome * @date 2023-12-21 */ @Service public class HotelRoomTypeServiceImpl implements IHotelRoomTypeService { @Autowired private HotelRoomTypeMapper hotelRoomTypeMapper; /** * 查询房间类型 * * @param roomTypeId 房间类型主键 * @return 房间类型 */ @Override public HotelRoomType selectHotelRoomTypeByRoomTypeId(Long roomTypeId) { return hotelRoomTypeMapper.selectHotelRoomTypeByRoomTypeId(roomTypeId); } /** * 查询房间类型列表 * * @param hotelRoomType 房间类型 * @return 房间类型 */ @Override public List<HotelRoomType> selectHotelRoomTypeList(HotelRoomType hotelRoomType) { return hotelRoomTypeMapper.selectHotelRoomTypeList(hotelRoomType); } /** * 新增房间类型 * * @param hotelRoomType 房间类型 * @return 结果 */ @Override public int insertHotelRoomType(HotelRoomType hotelRoomType) { // 1.防御性编程 Assert.notNull(hotelRoomType,"参数为空"); Assert.state(RegexUtils.testStringNoThreeBai(hotelRoomType.getRoomTypeName())&&RegexUtils.testStringNoThreeBai(hotelRoomType.getRoomTypeDescription()),"内容1到300位"); hotelRoomType.setCreateTime(DateUtils.getNowDate()); return hotelRoomTypeMapper.insertHotelRoomType(hotelRoomType); } /** * 修改房间类型 * * @param hotelRoomType 房间类型 * @return 结果 */ @Override public int updateHotelRoomType(HotelRoomType hotelRoomType) { // 1.防御性编程 Assert.notNull(hotelRoomType,"参数为空"); Assert.state(RegexUtils.testStringNoThreeBai(hotelRoomType.getRoomTypeName())&&RegexUtils.testStringNoThreeBai(hotelRoomType.getRoomTypeDescription()),"内容1到300位"); return hotelRoomTypeMapper.updateHotelRoomType(hotelRoomType); } /** * 批量删除房间类型 * * @param roomTypeIds 需要删除的房间类型主键 * @return 结果 */ @Override public int deleteHotelRoomTypeByRoomTypeIds(Long[] roomTypeIds) { for (Long id:roomTypeIds ) { Assert.notNull(hotelRoomTypeMapper.selectHotelRoomTypeByRoomTypeId(id),"参数异常"); } return hotelRoomTypeMapper.deleteHotelRoomTypeByRoomTypeIds(roomTypeIds); } /** * 删除房间类型信息 * * @param roomTypeId 房间类型主键 * @return 结果 */ @Override public int deleteHotelRoomTypeByRoomTypeId(Long roomTypeId) { // 1.防御性编程 HotelRoomType hotelRoomType = hotelRoomTypeMapper.selectHotelRoomTypeByRoomTypeId(roomTypeId); Assert.notNull(hotelRoomType,"参数异常"); return hotelRoomTypeMapper.deleteHotelRoomTypeByRoomTypeId(roomTypeId); } }
年少轻狂,总以为天下事竭力有为。人事尽时,终感力不能及。