javaEEday10-tlias-案例-部门管理-新增
This commit is contained in:
@@ -39,4 +39,15 @@ public class DeptController {
|
||||
deptService.deleteDept(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
//请求参数为json时{} [],要使用java的对象或者集合来接收
|
||||
@PostMapping("/depts")
|
||||
public Result addDept(@RequestBody Dept dept) {
|
||||
log.info("新增部门{}",dept);
|
||||
//调用业务层的新增部门方法
|
||||
deptService.addDept(dept);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.inmind.mapper;
|
||||
|
||||
import com.inmind.pojo.Dept;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@@ -14,4 +15,8 @@ public interface DeptMapper {
|
||||
|
||||
@Delete("delete from dept where id = #{id}")
|
||||
void deleteDept(Integer id);
|
||||
|
||||
@Insert("insert into dept (name, create_time, update_time) values " +
|
||||
"(#{name},#{createTime},#{updateTime})")
|
||||
void addDept(Dept dept);
|
||||
}
|
||||
|
||||
@@ -17,4 +17,10 @@ public interface DeptService {
|
||||
* @param id 部门id
|
||||
*/
|
||||
void deleteDept(Integer id);
|
||||
|
||||
/**
|
||||
* 新增部门
|
||||
* @param dept 部门信息
|
||||
*/
|
||||
void addDept(Dept dept);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.inmind.service.DeptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service //将当前类加载IOC容器(spring容器)进行管理
|
||||
@@ -31,4 +32,17 @@ public class DeptServiceImpl implements DeptService {
|
||||
//调用dao,执行删除部门操作
|
||||
deptMapper.deleteDept(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增部门功能
|
||||
* @param dept 部门信息
|
||||
*/
|
||||
@Override
|
||||
public void addDept(Dept dept) {
|
||||
//1.补充更新时间和创建时间
|
||||
dept.setCreateTime(LocalDateTime.now());
|
||||
dept.setUpdateTime(LocalDateTime.now());
|
||||
//2.调用mapper的新增功能
|
||||
deptMapper.addDept(dept);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user