mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
新增管理员的注册、登录、更改密码接口
This commit is contained in:
parent
a626863732
commit
132506deef
@ -0,0 +1,76 @@
|
||||
package cn.mafangui.hotel.controller;
|
||||
|
||||
import cn.mafangui.hotel.entity.Admin;
|
||||
import cn.mafangui.hotel.service.AdminService;
|
||||
import org.hibernate.validator.constraints.pl.REGON;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin")
|
||||
public class AdminController {
|
||||
@Autowired
|
||||
private AdminService adminService;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param userName
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/login")
|
||||
public int Login(String userName, String password){
|
||||
Admin admin = new Admin();
|
||||
admin.setUserName(userName);
|
||||
admin.setPassword(password);
|
||||
if (adminService.login(admin) == null){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @param userName
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/register")
|
||||
public int register(String userName, String password){
|
||||
Admin admin = new Admin();
|
||||
admin.setUserName(userName);
|
||||
admin.setPassword(password);
|
||||
return adminService.register(admin);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/updateProfile")
|
||||
public int updateProfile(String userName, String password){
|
||||
Admin admin = new Admin();
|
||||
admin.setUserName(userName);
|
||||
admin.setPassword(password);
|
||||
return adminService.updateProfile(admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找管理员
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getAdmin")
|
||||
public Admin getAdmin(String userName){
|
||||
return adminService.selectByUserName(userName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找所有管理员
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/getAllAdmin")
|
||||
public List<Admin> getAllAdmin(){
|
||||
return adminService.findAll();
|
||||
}
|
||||
}
|
@ -1,17 +1,21 @@
|
||||
package cn.mafangui.hotel.mapper;
|
||||
|
||||
import cn.mafangui.hotel.entity.Admin;
|
||||
import jdk.internal.dynalink.linker.LinkerServices;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public interface AdminMapper {
|
||||
int deleteByPrimaryKey(Integer adminId);
|
||||
|
||||
int insert(Admin record);
|
||||
|
||||
int insertSelective(Admin record);
|
||||
|
||||
Admin selectByPrimaryKey(Integer adminId);
|
||||
|
||||
int updateByPrimaryKeySelective(Admin record);
|
||||
|
||||
int updateByPrimaryKey(Admin record);
|
||||
Admin selectByUserName(String userName);
|
||||
Admin selectByUserNameAndPassword(Admin admin);
|
||||
int updateByUserNameSelective(Admin record);
|
||||
List<Admin> findAll();
|
||||
}
|
13
src/main/java/cn/mafangui/hotel/service/AdminService.java
Normal file
13
src/main/java/cn/mafangui/hotel/service/AdminService.java
Normal file
@ -0,0 +1,13 @@
|
||||
package cn.mafangui.hotel.service;
|
||||
|
||||
import cn.mafangui.hotel.entity.Admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AdminService {
|
||||
Admin login(Admin admin);
|
||||
int register(Admin admin);
|
||||
Admin selectByUserName(String userName);
|
||||
int updateProfile(Admin admin);
|
||||
List<Admin> findAll();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
import cn.mafangui.hotel.entity.Admin;
|
||||
import cn.mafangui.hotel.mapper.AdminMapper;
|
||||
import cn.mafangui.hotel.service.AdminService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class AdminServiceImpl implements AdminService {
|
||||
@Autowired
|
||||
private AdminMapper adminMapper;
|
||||
|
||||
@Override
|
||||
public Admin login(Admin admin) {
|
||||
return adminMapper.selectByUserNameAndPassword(admin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int register(Admin admin) {
|
||||
return adminMapper.insertSelective(admin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Admin selectByUserName(String userName) {
|
||||
return adminMapper.selectByUserName(userName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateProfile(Admin admin) {
|
||||
return adminMapper.updateByUserNameSelective(admin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Admin> findAll() {
|
||||
return adminMapper.findAll();
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public int register(User user) {
|
||||
return userMapper.insert(user);
|
||||
return userMapper.insertSelective(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,4 +39,6 @@ public class UserServiceImpl implements UserService {
|
||||
public int updateProfile(User user) {
|
||||
return userMapper.updateByUserNameSelective(user);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -39,12 +39,8 @@
|
||||
<if test="password != null">
|
||||
password,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="adminId != null">
|
||||
@ -56,12 +52,8 @@
|
||||
<if test="password != null">
|
||||
#{password,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.Admin">
|
||||
@ -90,4 +82,25 @@
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
where admin_id = #{adminId,jdbcType=INTEGER}
|
||||
</update>
|
||||
<select id="selectByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select * from admin
|
||||
where user_name = #{userName,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectByUserNameAndPassword" parameterType="cn.mafangui.hotel.entity.Admin">
|
||||
select * from admin
|
||||
where user_name = #{userName,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="findAll" resultMap="BaseResultMap">
|
||||
select * from admin
|
||||
</select>
|
||||
<update id="updateByUserNameSelective" parameterType="cn.mafangui.hotel.entity.Admin">
|
||||
update admin
|
||||
<set>
|
||||
<if test="password != null">
|
||||
password = #{password,jdbcType=VARCHAR},
|
||||
</if>
|
||||
update_time = now(),
|
||||
</set>
|
||||
where user_name = #{userName,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
@ -64,12 +64,8 @@
|
||||
<if test="idNumber != null">
|
||||
id_number,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">
|
||||
@ -96,12 +92,8 @@
|
||||
<if test="idNumber != null">
|
||||
#{idNumber,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.User">
|
||||
@ -186,12 +178,7 @@
|
||||
<if test="idNumber != null">
|
||||
id_number = #{idNumber,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
update_time = now(),
|
||||
</set>
|
||||
where user_name = #{userName,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
Loading…
x
Reference in New Issue
Block a user