javaEEday10-tlias-案例-部门管理-查询
This commit is contained in:
@@ -1,21 +1,34 @@
|
|||||||
package com.inmind.controller;
|
package com.inmind.controller;
|
||||||
|
|
||||||
|
import com.inmind.pojo.Dept;
|
||||||
import com.inmind.pojo.Result;
|
import com.inmind.pojo.Result;
|
||||||
|
import com.inmind.service.DeptService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@Slf4j//自动生成logback日志框架的对象log,在整个类中都可以直接使用logger
|
||||||
public class DeptController {
|
public class DeptController {
|
||||||
|
|
||||||
|
@Autowired//让spring容器进行依赖注入
|
||||||
|
private DeptService deptService;
|
||||||
|
|
||||||
//logback日志框架
|
//logback日志框架
|
||||||
private static Logger logger = LoggerFactory.getLogger("com.inmind.controller.DeptController");
|
//private static Logger logger = LoggerFactory.getLogger("com.inmind.controller.DeptController");
|
||||||
|
|
||||||
@RequestMapping("/depts")
|
@RequestMapping("/depts")
|
||||||
public Result deptList(){
|
public Result deptList(){
|
||||||
//接收请求
|
//接收请求
|
||||||
logger.info("查询全部部门数据请求");
|
log.info("查询全部部门数据请求");
|
||||||
return Result.success();
|
//调用业务层的查询部门的功能
|
||||||
|
List<Dept> deptList = deptService.deptList();
|
||||||
|
return Result.success(deptList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package com.inmind.mapper;
|
package com.inmind.mapper;
|
||||||
|
|
||||||
|
import com.inmind.pojo.Dept;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper //让mybatis框架识别,并自动生成实现类,发送sql给mysql获取数据的
|
@Mapper //让mybatis框架识别,并自动生成实现类,发送sql给mysql获取数据的
|
||||||
public interface DeptMapper {
|
public interface DeptMapper {
|
||||||
|
@Select("select * from dept")
|
||||||
|
List<Dept> deptList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
package com.inmind.service;
|
package com.inmind.service;
|
||||||
|
|
||||||
|
import com.inmind.pojo.Dept;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface DeptService {
|
public interface DeptService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有部门
|
||||||
|
* @return 部门的集合
|
||||||
|
*/
|
||||||
|
List<Dept> deptList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,24 @@
|
|||||||
package com.inmind.service.impl;
|
package com.inmind.service.impl;
|
||||||
|
|
||||||
|
import com.inmind.mapper.DeptMapper;
|
||||||
|
import com.inmind.pojo.Dept;
|
||||||
import com.inmind.service.DeptService;
|
import com.inmind.service.DeptService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service //将当前类加载IOC容器(spring容器)进行管理
|
@Service //将当前类加载IOC容器(spring容器)进行管理
|
||||||
public class DeptServiceImpl implements DeptService {
|
public class DeptServiceImpl implements DeptService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DeptMapper deptMapper;
|
||||||
|
|
||||||
|
//查询所有部门
|
||||||
|
@Override
|
||||||
|
public List<Dept> deptList() {
|
||||||
|
//调用mapper中功能,获取部门数据
|
||||||
|
List<Dept> deptList = deptMapper.deptList();
|
||||||
|
return deptList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user