mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-09-14 11:19:45 +08:00
添加酒店信息的基本操作
This commit is contained in:
114
src/main/java/cn/mafangui/hotel/controller/HotelController.java
Normal file
114
src/main/java/cn/mafangui/hotel/controller/HotelController.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package cn.mafangui.hotel.controller;
|
||||
|
||||
|
||||
import cn.mafangui.hotel.entity.Hotel;
|
||||
import cn.mafangui.hotel.service.HotelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/hotelInfo")
|
||||
public class HotelController {
|
||||
@Autowired
|
||||
private HotelService hotelService;
|
||||
/**
|
||||
* 添加酒店信息
|
||||
* @param hotelName
|
||||
* @param phone
|
||||
* @param telephone
|
||||
* @param email
|
||||
* @param address
|
||||
* @param website
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/add")
|
||||
public int addHotel(String hotelName,String phone,String telephone,String email,String address,String website){
|
||||
int result = 0;
|
||||
Hotel hotel = new Hotel(hotelName,phone,telephone,email,address,website);
|
||||
try {
|
||||
result = hotelService.addHotel(hotel);
|
||||
}catch (Exception e){
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除酒店信息
|
||||
* @param hotelId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/delete")
|
||||
public int deleteHotel(int hotelId){
|
||||
int result = 0;
|
||||
try {
|
||||
result = hotelService.deleteHotel(hotelId);
|
||||
}catch (Exception e){
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改酒店信息
|
||||
* @param hotelName
|
||||
* @param phone
|
||||
* @param telephone
|
||||
* @param email
|
||||
* @param address
|
||||
* @param website
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/update")
|
||||
public int updateHotel(int hotelId,String hotelName,String phone,String telephone,String email,String address,String website){
|
||||
int result = 0;
|
||||
Hotel hotel = new Hotel(hotelName,phone,telephone,email,address,website);
|
||||
hotel.setHotelId(hotelId);
|
||||
try{
|
||||
result = hotelService.updateHotel(hotel);
|
||||
}catch (Exception e){
|
||||
result = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param hotelId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/withId")
|
||||
public Hotel selectHotel(int hotelId){
|
||||
try {
|
||||
return hotelService.selectHotelById(hotelId);
|
||||
}catch (Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据酒店名查询
|
||||
* @param hotelName
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/withName")
|
||||
public Hotel selectHotel(String hotelName){
|
||||
try {
|
||||
return hotelService.selectHotelByName(hotelName);
|
||||
}catch (Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有酒店信息
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/all")
|
||||
public List<Hotel> allHotel(){
|
||||
return hotelService.findAllHotel();
|
||||
}
|
||||
}
|
@@ -92,4 +92,16 @@ public class Hotel {
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Hotel() {
|
||||
}
|
||||
|
||||
public Hotel(String hotelName, String phone, String telephone, String email, String address, String website) {
|
||||
this.hotelName = hotelName;
|
||||
this.phone = phone;
|
||||
this.telephone = telephone;
|
||||
this.email = email;
|
||||
this.address = address;
|
||||
this.website = website;
|
||||
}
|
||||
}
|
@@ -1,17 +1,20 @@
|
||||
package cn.mafangui.hotel.mapper;
|
||||
|
||||
import cn.mafangui.hotel.entity.Hotel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public interface HotelMapper {
|
||||
int deleteByPrimaryKey(Integer hotelId);
|
||||
|
||||
int insert(Hotel record);
|
||||
|
||||
int insertSelective(Hotel record);
|
||||
|
||||
Hotel selectByPrimaryKey(Integer hotelId);
|
||||
|
||||
int updateByPrimaryKeySelective(Hotel record);
|
||||
|
||||
int updateByPrimaryKey(Hotel record);
|
||||
|
||||
int insert(Hotel record);
|
||||
int insertSelective(Hotel record);
|
||||
int updateByPrimaryKeySelective(Hotel record);
|
||||
Hotel selectByPrimaryKey(Integer hotelId);
|
||||
Hotel selectByName(String hotelName);
|
||||
List<Hotel> selectAll();
|
||||
}
|
16
src/main/java/cn/mafangui/hotel/service/HotelService.java
Normal file
16
src/main/java/cn/mafangui/hotel/service/HotelService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.mafangui.hotel.service;
|
||||
|
||||
import cn.mafangui.hotel.entity.Hotel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HotelService {
|
||||
|
||||
int addHotel(Hotel hotel);
|
||||
int deleteHotel(int hotelId);
|
||||
int updateHotel(Hotel hotel);
|
||||
Hotel selectHotelByName(String hotelName);
|
||||
Hotel selectHotelById(int hotelId);
|
||||
List<Hotel> findAllHotel();
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
import cn.mafangui.hotel.entity.Hotel;
|
||||
import cn.mafangui.hotel.mapper.HotelMapper;
|
||||
import cn.mafangui.hotel.service.HotelService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HotelServiceImpl implements HotelService {
|
||||
@Autowired
|
||||
private HotelMapper hotelMapper;
|
||||
|
||||
@Override
|
||||
public int addHotel(Hotel hotel) {
|
||||
return hotelMapper.insertSelective(hotel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteHotel(int hotelId) {
|
||||
return hotelMapper.deleteByPrimaryKey(hotelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateHotel(Hotel hotel) {
|
||||
return hotelMapper.updateByPrimaryKeySelective(hotel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hotel selectHotelByName(String hotelName) {
|
||||
return hotelMapper.selectByName(hotelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hotel selectHotelById(int hotelId) {
|
||||
return hotelMapper.selectByPrimaryKey(hotelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Hotel> findAllHotel() {
|
||||
return hotelMapper.selectAll();
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@
|
||||
)
|
||||
values (#{hotelId,jdbcType=INTEGER}, #{hotelName,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
|
||||
#{telephone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
|
||||
#{website,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
|
||||
#{website,jdbcType=VARCHAR}, now(),now()
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Hotel">
|
||||
@@ -59,12 +59,8 @@
|
||||
<if test="website != null">
|
||||
website,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="hotelId != null">
|
||||
@@ -88,12 +84,8 @@
|
||||
<if test="website != null">
|
||||
#{website,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
#{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
now(),
|
||||
now(),
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Hotel">
|
||||
@@ -138,4 +130,15 @@
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
||||
</update>
|
||||
<select id="selectAll" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from hotel_info
|
||||
</select>
|
||||
<select id="selectByName" parameterType="String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from hotel_info
|
||||
where hotel_name = #{hotelName,jdbcType=VARCHAR}
|
||||
</select>
|
||||
</mapper>
|
Reference in New Issue
Block a user