tlias管理系统-部门查询功能实现
This commit is contained in:
@@ -1,7 +1,35 @@
|
||||
package com.inmind.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.inmind.pojo.Dept;
|
||||
import com.inmind.pojo.Result;
|
||||
import com.inmind.service.DeptService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class DeptController {
|
||||
|
||||
//private static Logger log = LoggerFactory.getLogger(DeptController.class);//固定代码,很多类中都要写
|
||||
|
||||
@Autowired
|
||||
private DeptService deptService;
|
||||
|
||||
/*
|
||||
查询部门
|
||||
*/
|
||||
//@RequestMapping(value = "/depts",method = RequestMethod.GET)
|
||||
@GetMapping("/depts")
|
||||
public Result list(){
|
||||
// System.out.println("查询全部部门数据");
|
||||
log.info("查询全部部门数据");
|
||||
//调用service查询部门数据
|
||||
List<Dept> deptList = deptService.list();
|
||||
return Result.success(deptList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.inmind.mapper;
|
||||
|
||||
import com.inmind.pojo.Dept;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DeptMapper {
|
||||
@Select("select * from dept")
|
||||
List<Dept> list();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.inmind.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Result {
|
||||
private Integer code;//1:成功 0:失败
|
||||
private String msg;//提示信息
|
||||
private Object data;//数据data
|
||||
|
||||
|
||||
//封装一些固定的成功和失败的方法,供外部调用
|
||||
public static Result success(){
|
||||
/*Result result = new Result(1, "成功", null);
|
||||
return result;*/
|
||||
return success(null);
|
||||
}
|
||||
|
||||
public static Result success(Object data){
|
||||
Result result = new Result(1, "成功", data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Result error(String msg){
|
||||
Result result = new Result(0, msg, null);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
package com.inmind.service;
|
||||
|
||||
import com.inmind.pojo.Dept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeptService {
|
||||
//查询部门列表数据
|
||||
List<Dept> list();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
package com.inmind.service.impl;
|
||||
|
||||
import com.inmind.mapper.DeptMapper;
|
||||
import com.inmind.pojo.Dept;
|
||||
import com.inmind.service.DeptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DeptServiceImpl implements DeptService {
|
||||
|
||||
@Autowired
|
||||
private DeptMapper deptMapper;
|
||||
|
||||
@Override
|
||||
public List<Dept> list() {
|
||||
//调用deptMapper获取部门列表数据
|
||||
List<Dept> deptList = deptMapper.list();
|
||||
return deptList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user