mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-11-04 14:34:47 +08:00 
			
		
		
		
	完成酒店信息接口编写
This commit is contained in:
		@@ -0,0 +1,49 @@
 | 
			
		||||
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 = "/hotel")
 | 
			
		||||
public class HotelController {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private HotelService hotelService;
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/add")
 | 
			
		||||
    public int addHotel(String hotelName,String phone,String telephone,String email,String address,String website){
 | 
			
		||||
        Hotel hotel = new Hotel(hotelName,phone,telephone,email,address,website);
 | 
			
		||||
        return hotelService.insert(hotel);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/delete")
 | 
			
		||||
    public int deleteHotel(int hotelId){
 | 
			
		||||
        return hotelService.delete(hotelId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/update")
 | 
			
		||||
    public int updateHotel(int hotelId,String hotelName,String phone,String telephone,String email,String address,String website){
 | 
			
		||||
        Hotel hotel = new Hotel(hotelName,phone,telephone,email,address,website);
 | 
			
		||||
        hotel.setHotelId(hotelId);
 | 
			
		||||
        return hotelService.update(hotel);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/withId")
 | 
			
		||||
    public Hotel getById(int hotelId){
 | 
			
		||||
        return hotelService.selectById(hotelId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/withName")
 | 
			
		||||
    public Hotel getById(String hotelName){
 | 
			
		||||
        return hotelService.selectByName(hotelName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/all")
 | 
			
		||||
    public List<Hotel> getAllHotel(){
 | 
			
		||||
        return hotelService.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -15,6 +15,12 @@ public class UserController {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private UserService userService;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 用户登录
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @param password
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/login")
 | 
			
		||||
    public int userLogin(String username,String password){
 | 
			
		||||
        int result = 0;
 | 
			
		||||
@@ -25,12 +31,35 @@ public class UserController {
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 用户注册
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @param password
 | 
			
		||||
     * @param name
 | 
			
		||||
     * @param gender
 | 
			
		||||
     * @param phone
 | 
			
		||||
     * @param email
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @param idcard
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/register")
 | 
			
		||||
    public int userRegister(String username,String password,String name,String gender,String phone,String email,String address,String idcard){
 | 
			
		||||
        User user = new User(username,password,name,gender,phone,email,address,idcard);
 | 
			
		||||
        return userService.insertUser(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新用户信息
 | 
			
		||||
     * @param userId
 | 
			
		||||
     * @param name
 | 
			
		||||
     * @param gender
 | 
			
		||||
     * @param phone
 | 
			
		||||
     * @param email
 | 
			
		||||
     * @param address
 | 
			
		||||
     * @param idcard
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/update")
 | 
			
		||||
    public int userUpdate(int userId,String name,String gender,String phone,String email,String address,String idcard){
 | 
			
		||||
        User user = new User();
 | 
			
		||||
@@ -44,6 +73,13 @@ public class UserController {
 | 
			
		||||
        return userService.updateUser(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更改密码
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @param oldPassword
 | 
			
		||||
     * @param newPassword
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/updatePassword")
 | 
			
		||||
    public int updatePassword(String username,String oldPassword,String newPassword){
 | 
			
		||||
        User user = userService.selectByUsernameAndPassword(username,oldPassword);
 | 
			
		||||
@@ -55,11 +91,20 @@ public class UserController {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 所有用户
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(value = "/all")
 | 
			
		||||
    public List<User> getAllUser(){
 | 
			
		||||
        return userService.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断用户名是否存在
 | 
			
		||||
     * @param username
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/isUsernameExist")
 | 
			
		||||
    public int isUsernameExist(String username){
 | 
			
		||||
        int result = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -92,4 +92,31 @@ 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "Hotel{" +
 | 
			
		||||
                "hotelId=" + hotelId +
 | 
			
		||||
                ", hotelName='" + hotelName + '\'' +
 | 
			
		||||
                ", phone='" + phone + '\'' +
 | 
			
		||||
                ", telephone='" + telephone + '\'' +
 | 
			
		||||
                ", email='" + email + '\'' +
 | 
			
		||||
                ", address='" + address + '\'' +
 | 
			
		||||
                ", website='" + website + '\'' +
 | 
			
		||||
                ", createTime=" + createTime +
 | 
			
		||||
                ", updateTime=" + updateTime +
 | 
			
		||||
                '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,11 @@
 | 
			
		||||
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);
 | 
			
		||||
 | 
			
		||||
@@ -11,7 +15,13 @@ public interface HotelMapper {
 | 
			
		||||
 | 
			
		||||
    Hotel selectByPrimaryKey(Integer hotelId);
 | 
			
		||||
 | 
			
		||||
    Hotel selectByName(String hotelName);
 | 
			
		||||
 | 
			
		||||
    List<Hotel> selectAll();
 | 
			
		||||
 | 
			
		||||
    int updateByPrimaryKeySelective(Hotel record);
 | 
			
		||||
 | 
			
		||||
    int updateByPrimaryKey(Hotel record);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -6,11 +6,11 @@ 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();
 | 
			
		||||
    int insert(Hotel hotel);
 | 
			
		||||
    int delete(int hotelId);
 | 
			
		||||
    int update(Hotel hotel);
 | 
			
		||||
    Hotel selectByName(String hotelName);
 | 
			
		||||
    Hotel selectById(int hotelId);
 | 
			
		||||
    List<Hotel> selectAll();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,46 @@
 | 
			
		||||
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 insert(Hotel hotel) {
 | 
			
		||||
        return hotelMapper.insertSelective(hotel);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int delete(int hotelId) {
 | 
			
		||||
        return hotelMapper.deleteByPrimaryKey(hotelId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int update(Hotel hotel) {
 | 
			
		||||
        return hotelMapper.updateByPrimaryKeySelective(hotel);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Hotel selectByName(String hotelName) {
 | 
			
		||||
        return hotelMapper.selectByName(hotelName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Hotel selectById(int hotelId) {
 | 
			
		||||
        return hotelMapper.selectByPrimaryKey(hotelId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Hotel> selectAll() {
 | 
			
		||||
        return hotelMapper.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user