添加对操作员的简单操作

This commit is contained in:
freeebird
2018-10-16 20:35:42 +08:00
parent 9c7af9d032
commit 931447aa39
7 changed files with 263 additions and 18 deletions

View File

@@ -0,0 +1,54 @@
package cn.mafangui.hotel.controller;
import cn.mafangui.hotel.entity.Worker;
import cn.mafangui.hotel.service.WorkerService;
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 = "/worker")
public class WorkerController {
@Autowired
private WorkerService workerService;
@RequestMapping(method = RequestMethod.POST,value = "/login")
public int login(String userName,String password){
Worker worker = new Worker(userName,password);
if (workerService.login(worker) !=null ){
return 1;
}else {
return 0;
}
}
@RequestMapping(method = RequestMethod.POST,value = "/add")
public int addWorker(String userName,String password,String workerName,String phone,String email,String address){
Worker worker = new Worker(userName,password,workerName,phone,email,address);
return workerService.addWorker(worker);
}
@RequestMapping(method = RequestMethod.POST,value = "/del")
public int delWorker(String userName){
return workerService.delWorker(userName);
}
@RequestMapping(method = RequestMethod.POST,value = "/update")
public int updateWorker(String userName,String password,String workerName,String phone,String email,String address){
Worker worker = new Worker(userName,password,workerName,phone,email,address);
return workerService.updateWorker(worker);
}
@RequestMapping(value = "/query")
public Worker queryWorker(String userName){
return workerService.selectWorker(userName);
}
@RequestMapping(value = "/all")
public List<Worker> findAllWorkers(){
return workerService.findAllWorker();
}
}

View File

@@ -92,4 +92,36 @@ public class Worker {
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Worker() {
}
public Worker(String userName, String password) {
this.userName = userName;
this.password = password;
}
public Worker(String userName, String password, String workerName, String phone, String email, String address) {
this.userName = userName;
this.password = password;
this.workerName = workerName;
this.phone = phone;
this.email = email;
this.address = address;
}
@Override
public String toString() {
return "Worker{" +
"workerId=" + workerId +
", userName='" + userName + '\'' +
", password='" + password + '\'' +
", workerName='" + workerName + '\'' +
", phone='" + phone + '\'' +
", email='" + email + '\'' +
", address='" + address + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}

View File

@@ -1,7 +1,11 @@
package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Worker;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface WorkerMapper {
int deleteByPrimaryKey(Integer workerId);
@@ -14,4 +18,10 @@ public interface WorkerMapper {
int updateByPrimaryKeySelective(Worker record);
int updateByPrimaryKey(Worker record);
int deleteByUserName(String userName);
int updateByUserNameSelective(Worker record);
Worker selectByUserName(String userName);
List<Worker> findAll();
Worker selectByUserNameAndPassword(Worker worker);
}

View File

@@ -0,0 +1,15 @@
package cn.mafangui.hotel.service;
import cn.mafangui.hotel.entity.Worker;
import java.util.List;
public interface WorkerService {
int addWorker(Worker worker);
int delWorker(String userName);
int updateWorker(Worker worker);
Worker selectWorker(String userName);
List<Worker> findAllWorker();
Worker login(Worker worker);
}

View File

@@ -0,0 +1,46 @@
package cn.mafangui.hotel.service.impl;
import cn.mafangui.hotel.entity.Worker;
import cn.mafangui.hotel.mapper.WorkerMapper;
import cn.mafangui.hotel.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class WorkerServiceImpl implements WorkerService {
@Autowired
private WorkerMapper workerMapper;
@Override
public int addWorker(Worker worker) {
return workerMapper.insertSelective(worker);
}
@Override
public int delWorker(String userName) {
return workerMapper.deleteByUserName(userName);
}
@Override
public int updateWorker(Worker worker) {
return workerMapper.updateByUserNameSelective(worker);
}
@Override
public Worker selectWorker(String userName) {
return workerMapper.selectByUserName(userName);
}
@Override
public List<Worker> findAllWorker() {
return workerMapper.findAll();
}
@Override
public Worker login(Worker worker) {
return workerMapper.selectByUserNameAndPassword(worker);
}
}