tlias管理系统-新增部门功能实现

This commit is contained in:
2025-10-09 14:25:30 +08:00
parent affa6356b8
commit cd606ccc25
4 changed files with 32 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import java.util.List;
@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {
//private static Logger log = LoggerFactory.getLogger(DeptController.class);//固定代码,很多类中都要写
@@ -24,7 +25,7 @@ public class DeptController {
查询部门
*/
//@RequestMapping(value = "/depts",method = RequestMethod.GET)
@GetMapping("/depts")
@GetMapping
public Result list(){
// System.out.println("查询全部部门数据");
log.info("查询全部部门数据");
@@ -36,10 +37,20 @@ public class DeptController {
/*
删除部门
*/
@DeleteMapping("/depts/{id}")
@DeleteMapping("/{id}")
public Result delete(@PathVariable Integer id){
log.info("删除部门:{}",id);
deptService.delete(id);
return Result.success();
}
/*
新增部门
*/
@PostMapping
public Result add(@RequestBody Dept dept){
log.info("新增部门:{}",dept);
deptService.add(dept);
return Result.success();
}
}

View File

@@ -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;
@@ -16,4 +17,9 @@ public interface DeptMapper {
//根据id删除部门
@Delete("delete from dept where id = #{id}")
void delete(Integer id);
//新增部门
@Insert("insert into dept (name, create_time, update_time) " +
"VALUES (#{name},#{createTime},#{updateTime})")
void insert(Dept dept);
}

View File

@@ -10,4 +10,7 @@ public interface DeptService {
//根据id删除部门
void delete(Integer id);
//新增部门
void add(Dept dept);
}

View File

@@ -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
@@ -26,4 +27,13 @@ public class DeptServiceImpl implements DeptService {
public void delete(Integer id) {
deptMapper.delete(id);
}
//新增部门
@Override
public void add(Dept dept) {
//补充基础属性,创建时间和更新时间
dept.setCreateTime(LocalDateTime.now());
dept.setUpdateTime(LocalDateTime.now());
deptMapper.insert(dept);
}
}