Mybatis注解实现SQL语句

12 篇文章 1 订阅

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');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

君问归期魏有期

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值