Mybatis注解实现SQL语句
增
@Insert("insert into blog values(null,'河师大报', '魏欣', '2022-02-23', '99')")
void insertBlog();
删
@Delete("delete from blog where id =4")
void deleteBlog();
查
@Select("Select * from blog where id =4")
// 因为查询出来的是一条数据,我的数据实体是Blog,那么我们返回Blog类型数据
Blog getBlog();
改
@Update("update blog set author ='404-魏同学' where id =3")
void updateBlog();
数据库表
/*
Navicat MySQL Data Transfer
Source Server : fiveGods
Source Server Version : 80016
Source Host : localhost:3306
Source Database : db10
Target Server Type : MYSQL
Target Server Version : 80016
File Encoding : 65001
Date: 2022-02-23 16:12:27
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for blog
-- ----------------------------
DROP TABLE IF EXISTS `blog`;
CREATE TABLE `blog` (
`id` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT '博客id',
`title` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '博客标题',
`author` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '博客作者',
`create_time` date NOT NULL COMMENT '创建时间',
`views` int(30) NOT NULL COMMENT '浏览量',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
-- ----------------------------
-- Records of blog
-- ----------------------------
INSERT INTO `blog` VALUES ('0000000001', '河师大报', '师大人', '2022-02-23', '99');