1. 数据库 数据库名:brog_database 表名:comments 字段看下图
2. 留言板项目目录: springboot+mysql+idea+postman
3. com.oy.demo.controller MessageController.java
package com.oy.demo.controller;
import com.oy.demo.pojo.Message;
import com.oy.demo.service.MessageService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("message")
public class MessageController {
@Resource
private MessageService messageService;
/**
* 找到所有留言信息
* @return
*/
@PostMapping("find")
public List<Message> findAllMessage(){
return messageService.findAllMessage();
}
/**
* 发送一条留言信息
* @param message
* @return
*/
@PostMapping("add")
public Map<String, Object> addMessage(@RequestBody Message message){
// System.out.println("============================"+message);
return messageService.addMessage(message);
}
}
4. com.oy.demo.controller UiController.java