mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
完成酒店信息接口编写
This commit is contained in:
parent
c8124bbc70
commit
f7ea1c33eb
@ -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
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户登录
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/login")
|
@RequestMapping(method = RequestMethod.POST,value = "/login")
|
||||||
public int userLogin(String username,String password){
|
public int userLogin(String username,String password){
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -25,12 +31,35 @@ public class UserController {
|
|||||||
return result;
|
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")
|
@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){
|
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);
|
User user = new User(username,password,name,gender,phone,email,address,idcard);
|
||||||
return userService.insertUser(user);
|
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")
|
@RequestMapping(method = RequestMethod.POST,value = "/update")
|
||||||
public int userUpdate(int userId,String name,String gender,String phone,String email,String address,String idcard){
|
public int userUpdate(int userId,String name,String gender,String phone,String email,String address,String idcard){
|
||||||
User user = new User();
|
User user = new User();
|
||||||
@ -44,6 +73,13 @@ public class UserController {
|
|||||||
return userService.updateUser(user);
|
return userService.updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更改密码
|
||||||
|
* @param username
|
||||||
|
* @param oldPassword
|
||||||
|
* @param newPassword
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/updatePassword")
|
@RequestMapping(method = RequestMethod.POST,value = "/updatePassword")
|
||||||
public int updatePassword(String username,String oldPassword,String newPassword){
|
public int updatePassword(String username,String oldPassword,String newPassword){
|
||||||
User user = userService.selectByUsernameAndPassword(username,oldPassword);
|
User user = userService.selectByUsernameAndPassword(username,oldPassword);
|
||||||
@ -55,11 +91,20 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有用户
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/all")
|
@RequestMapping(value = "/all")
|
||||||
public List<User> getAllUser(){
|
public List<User> getAllUser(){
|
||||||
return userService.selectAll();
|
return userService.selectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断用户名是否存在
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(method = RequestMethod.POST,value = "/isUsernameExist")
|
@RequestMapping(method = RequestMethod.POST,value = "/isUsernameExist")
|
||||||
public int isUsernameExist(String username){
|
public int isUsernameExist(String username){
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -92,4 +92,31 @@ public class Hotel {
|
|||||||
public void setUpdateTime(Date updateTime) {
|
public void setUpdateTime(Date updateTime) {
|
||||||
this.updateTime = 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;
|
package cn.mafangui.hotel.mapper;
|
||||||
|
|
||||||
import cn.mafangui.hotel.entity.Hotel;
|
import cn.mafangui.hotel.entity.Hotel;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
public interface HotelMapper {
|
public interface HotelMapper {
|
||||||
int deleteByPrimaryKey(Integer hotelId);
|
int deleteByPrimaryKey(Integer hotelId);
|
||||||
|
|
||||||
@ -11,7 +15,13 @@ public interface HotelMapper {
|
|||||||
|
|
||||||
Hotel selectByPrimaryKey(Integer hotelId);
|
Hotel selectByPrimaryKey(Integer hotelId);
|
||||||
|
|
||||||
|
Hotel selectByName(String hotelName);
|
||||||
|
|
||||||
|
List<Hotel> selectAll();
|
||||||
|
|
||||||
int updateByPrimaryKeySelective(Hotel record);
|
int updateByPrimaryKeySelective(Hotel record);
|
||||||
|
|
||||||
int updateByPrimaryKey(Hotel record);
|
int updateByPrimaryKey(Hotel record);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -6,11 +6,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface HotelService {
|
public interface HotelService {
|
||||||
|
|
||||||
int addHotel(Hotel hotel);
|
int insert(Hotel hotel);
|
||||||
int deleteHotel(int hotelId);
|
int delete(int hotelId);
|
||||||
int updateHotel(Hotel hotel);
|
int update(Hotel hotel);
|
||||||
Hotel selectHotelByName(String hotelName);
|
Hotel selectByName(String hotelName);
|
||||||
Hotel selectHotelById(int hotelId);
|
Hotel selectById(int hotelId);
|
||||||
List<Hotel> findAllHotel();
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,17 @@
|
|||||||
from hotel_info
|
from hotel_info
|
||||||
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectByName" parameterType="String" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from hotel_info
|
||||||
|
where hotel_name = #{hotelName,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
<select id="selectAll" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from hotel_info
|
||||||
|
</select>
|
||||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||||
delete from hotel_info
|
delete from hotel_info
|
||||||
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
||||||
@ -59,12 +70,8 @@
|
|||||||
<if test="website != null">
|
<if test="website != null">
|
||||||
website,
|
website,
|
||||||
</if>
|
</if>
|
||||||
<if test="createTime != null">
|
|
||||||
create_time,
|
create_time,
|
||||||
</if>
|
|
||||||
<if test="updateTime != null">
|
|
||||||
update_time,
|
update_time,
|
||||||
</if>
|
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="hotelId != null">
|
<if test="hotelId != null">
|
||||||
@ -88,12 +95,8 @@
|
|||||||
<if test="website != null">
|
<if test="website != null">
|
||||||
#{website,jdbcType=VARCHAR},
|
#{website,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
<if test="createTime != null">
|
now(),
|
||||||
#{createTime,jdbcType=TIMESTAMP},
|
now(),
|
||||||
</if>
|
|
||||||
<if test="updateTime != null">
|
|
||||||
#{updateTime,jdbcType=TIMESTAMP},
|
|
||||||
</if>
|
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Hotel">
|
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Hotel">
|
||||||
@ -117,12 +120,7 @@
|
|||||||
<if test="website != null">
|
<if test="website != null">
|
||||||
website = #{website,jdbcType=VARCHAR},
|
website = #{website,jdbcType=VARCHAR},
|
||||||
</if>
|
</if>
|
||||||
<if test="createTime != null">
|
update_time = now(),
|
||||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
|
||||||
</if>
|
|
||||||
<if test="updateTime != null">
|
|
||||||
update_time = #{updateTime,jdbcType=TIMESTAMP},
|
|
||||||
</if>
|
|
||||||
</set>
|
</set>
|
||||||
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
where hotel_id = #{hotelId,jdbcType=INTEGER}
|
||||||
</update>
|
</update>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user