4 changed files with 68 additions and 0 deletions
@ -0,0 +1,9 @@ |
|||
import request from '@/utils/request'; |
|||
|
|||
|
|||
export function twdelete(id){ |
|||
return request({ |
|||
url: `/twdelete/${id}`, // 使用模板字符串来包含变量
|
|||
method: 'delete', |
|||
}); |
|||
} |
|||
@ -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("删除失败"); |
|||
} |
|||
} |
|||
} |
|||
@ -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删除记录
|
|||
} |
|||
@ -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…
Reference in new issue