0

I was able to create values and store into my db, which displays a view of the list of values stored and additional values that is written into a input will automatically show in the table.

Controller

@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";
}

Repository

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>

Problem

In my controller the delete would not execute(it is not doing what I want it to do). but line below it redirects me back to the same page.

What am I doing wrong? I have been savaging through the internet trying to find the crud functions for mongodb using springboot. Logically speaking why wouldn't my delete work if I follow the logic of the create?

I followed Tutorial, for posting to a table. Then I followed Tutorial 2 That implements my delete and update. But It does not delete the values.

JayC
  • 2,144
  • 8
  • 42
  • 77
  • Where did you get that error from ? Can you add the stack trace ? Did you check to see if the id is being pass correctly to the controller function ? Why is delete method using GET ? It should be one of the write http verb. – s7vr Dec 19 '16 at 20:58
  • I don't know know how to get the stack trace, But I'll add the whole error onto my post. I am getting the error from my Controller. "ID". – JayC Dec 19 '16 at 21:04

0 Answers0