Spring boot+mybatis+mysql实现数据库插入操作
1、参考之前的案例,该案例中已经实现了mysql数据库的数据信息的单条插入和查询功能
2、实现数据信息的插入功能在VideoInfoMapper类中增加侑喏嵋甲插入数据的功能函数package image.dao;import or爿讥旌护g.apache.ibatis.annotations.Insert;import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;@Mapperpublic interface VideoInfoMapper { @Select("select * from Video_info where id=#{id}") VideoInfo findById(@Param("id") int id); @Insert("insert into video_info(fileName,filePath,author,createDate) values(#{fileName},#{filePath},#{author},sysdate())") int insertVideoInfo(@Param("fileName") String fileName,@Param("filePath") String filePath,@Param("author") String author); }

4、在VideoInfoController 控制器类中,增加数据插入的Restful web service服务接口insertVideo:/video/addpa艘早祓胂ckage image;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import image.dao.VideoInfo;import image.dao.VideoService;@RestController@RequestMapping("/video")public class VideoInfoController { final static Logger logger = LoggerFactory.getLogger(VideoInfoController.class); @Autowired private VideoService videoService; @RequestMapping("/info/{id}") public VideoInfo getVideoInfo(@PathVariable("id") int id) { return videoService.getVideoInfo(id); } @RequestMapping("/add") public int insertVideo(@RequestParam String fileName,@RequestParam String filePath,@RequestParam String author) { int res =-1; res=videoService.insertVideoInfo(fileName, filePath, author); return res; } }

6、在页面中端到端实现视频信息的入库、修改和删除等操作1) 在页面中通过http://localhost:8080/uploadVideo 页面进行视频文件上传2)视频文件上传完成后,到mysql数据库中查询video_info表,验证数据是否插入到数据库中

