mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-11-02 05:24:46 +08:00
新增管理员的注册、登录、更改密码接口
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user