控制器中的CRUD未正确删除行

时间:2016-12-19 20:54:32

标签: java spring mongodb spring-boot

我能够创建值并存储到我的数据库中,该数据库显示存储的值列表的视图,并且写入输入的其他值将自动显示在表中。

控制器

@Controller
public class AppPortController {

    private ApServerService apServerService;

    @Autowired
    public void setApServerService(ApServerService apServerService) {
        this.apServerService = apServerService;
    }

@RequestMapping(value = "/editApServer", method = RequestMethod.GET)
public String list(Model model) {
    model.addAttribute("apList", apServerService.listAllApServerModels());
    return "editApServer";
}

@RequestMapping("editApServer/update/{id}")
public String update(@PathVariable String id, Model model) {
    model.addAttribute("apList", apServerService.getApServerModelById(id));
    return "editApServer";
}

@RequestMapping("editApServer/new")
public String newServer(Model model){
    model.addAttribute("apServer", new ApServerModel());
    return "editApServer";
}

@RequestMapping(value = "/addServer", method = RequestMethod.POST)
public String addServer(@ModelAttribute ApServerModel apServerModel) {
    apServerService.saveApServerModel(apServerModel);

    return "redirect:editApServer";
}


@RequestMapping("editApServer/delete")
public String delete(@PathVariable String host){
    apServerService.deleteApServerModel(host);

    return "redirect:editApServer";
}

存储库

public interface AppPortRepository extends CrudRepository<ApServerModel, String> {}

POJO

@Document(collection = "apDBServer")
public class ApServerModel {

    @Id
    private String id;
    private String host;
    private String port;

//getters and setters

HTML SNIPPET

<table>
    <thead>
    <tr>
        <th> Host Name </th>
        <th> Port Name</th>
        <th>Id</th>
        <th></th>
        <th></th>

    </tr>
    </thead>
    <tbody>
    <tr th:each="ApServerModel : ${apList}">        
        <td th:text ="${ApServerModel.host}"></td>
        <td th:text ="${ApServerModel.port}"></td>
        <td th:text ="${ApServerModel.id}"></td>
        <td><a th:href="${'editApServer/update/' + ApServerModel.id}">Edit</a></td>
        <td><a th:href="${'editApServer/delete'}">Delete</a></td>

    </tr>
    </tbody>
</table>

<br />
        <h2>Add AppPortServer</h2>
        <form action="/addServer" method="POST">
            Host <input type="text" id="host" name="host" /><br />
            Port <input type="text" id="port" name="port" /><br />
            <input type="submit" />
        </form>

问题

在我的控制器中,删除不会执行(它没有按照我想要的方式执行)。但是它下方的行将我重新定向回同一页面。

我做错了什么?我一直在通过互联网进行搜索,试图使用springboot找到mongodb的crud函数。从逻辑上讲,如果我遵循创建的逻辑,为什么我的删除工作不起作用?

我跟着Tutorial,张贴到桌子上。然后我跟着 Tutorial 2实现我的删除和更新。但它不会删除这些值。

0 个答案:

没有答案