ChenYao 1 year ago
parent
commit
0461b133bc
  1. 9
      kcui/src/api/twdelete.js
  2. 29
      src/main/java/com/main/woka/Web/Controller/TwDeleteController.java
  3. 10
      src/main/java/com/main/woka/Web/Mapper/TwDeleteMapper.java
  4. 20
      src/main/java/com/main/woka/Web/Service/TwDeleteService.java

9
kcui/src/api/twdelete.js

@ -0,0 +1,9 @@
import request from '@/utils/request';
export function twdelete(id){
return request({
url: `/twdelete/${id}`, // 使用模板字符串来包含变量
method: 'delete',
});
}

29
src/main/java/com/main/woka/Web/Controller/TwDeleteController.java

@ -0,0 +1,29 @@
package com.main.woka.Web.Controller;
import com.main.woka.Common.core.AjaxResult;
import com.main.woka.Web.Service.TwDeleteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/twdelete")
public class TwDeleteController extends BaseController {
@Autowired
private TwDeleteService twDeleteService;
@DeleteMapping("/{id}")
public AjaxResult deleteItem(@PathVariable Long id) {
try {
// 调用服务层方法进行删除操作
twDeleteService.deleteItem(id);
return AjaxResult.success();
} catch (Exception e) {
// 返回错误信息
e.printStackTrace();
return AjaxResult.error("删除失败");
}
}
}

10
src/main/java/com/main/woka/Web/Mapper/TwDeleteMapper.java

@ -0,0 +1,10 @@
package com.main.woka.Web.Mapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TwDeleteMapper {
@Delete("DELETE FROM kc_info WHERE id = #{id}")
void deleteById(Long id); // 根据ID删除记录
}

20
src/main/java/com/main/woka/Web/Service/TwDeleteService.java

@ -0,0 +1,20 @@
package com.main.woka.Web.Service;
import com.main.woka.Web.Mapper.TwDeleteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TwDeleteService {
private final TwDeleteMapper twDeleteMapper;
@Autowired
public TwDeleteService(TwDeleteMapper twDeleteMapper) {
this.twDeleteMapper = twDeleteMapper;
}
public void deleteItem(Long id) {
// 调用Mapper执行数据库删除操作
twDeleteMapper.deleteById(id);
}
}
Loading…
Cancel
Save