tkmybatis是什么?

  tkmybatis是为了简化mybatis单表的增删改查而诞生的,极其方便的使用MyBatis单表的增删改查,在使用mybatis单表增删改查时,可以直接调用tkmybatis中提供的方法直接调用而不用写xml配置文件。支持单表操作,不支持通用的多表联合查询。

  Springboot整合tkmybatis

  pom.xml:

  org.springframework.boot

  spring-boot-starter-web

  org.springframework.boot

  spring-boot-devtools

  runtime

  true

  org.springframework.boot

  spring-boot-starter-test

  test

  tk.mybatis

  mapper

  4.1.5

  tk.mybatis

  mapper-spring-boot-starter

  2.1.5

  mysql

  mysql-connector-java

  runtime

  org.projectlombok

  lombok

  true

  UserController:

  @RestController

  public class UserController {

  @Autowired

  private UserService userService;

  @RequestMapping("/findById/{id}")

  public User findById(@PathVariable int id) {

  User user = userService.findById(id);

  return user;

  }

  @RequestMapping("/findAll")

  public List findAll() {

  List userList = userService.findAll();

  return userList;

  }

  @RequestMapping("/insert")

  public void insert() {

  User user = new User();

  user.setName("张三");

  user.setSex("男");

  user.setAge(18);

  user.setAddress("江西省");

  user.setPhone("456789645");

  userService.insert(user);

  }

  @RequestMapping("/delete")

  public void delete() {

  User user = new User();

  user.setId(5);

  userService.delete(user);

  }

  @RequestMapping("/update")

  public void update() {

  User user = new User();

  user.setId(5);

  user.setName("李四");

  userService.update(user);

  }

  }

  UserService:

  public interface UserService {

  public User findById(int id);

  public List findAll();

  public void insert(User user);

  public void update(User user);

  public void delete(User user);

  }

  UserServiceImpl:

  @Service

  public class UserServiceImpl implements UserService {

  @Autowired

  private UserMapper userMapper;

  @Override

  public User findById(int id) {

  return userMapper.selectByPrimaryKey(id);

  }

  @Override

  public List findAll() {

  return userMapper.selectAll();

  }

  @Override

  public void insert(User user) {

  userMapper.insertSelective(user);

  }

  @Override

  public void update(User user) {

  userMapper.updateByPrimaryKey(user);

  }无锡人流医院 http://xmobile.wxbhnk120.com/

  @Override

  public void delete(User user) {

  userMapper.deleteByPrimaryKey(user);

  }

  }

  UserMapper:

  public interface UserMapper extends Mapper {

  }

  application.properties:

  #tomcat port

  server.port=8080

  #datasource

  spring.datasource.driver-class-name=com.mysql.jdbc.Driver

  spring.datasource.url=jdbc:mysql://188.131.247.26:3306/

  spring.datasource.username=root

  spring.datasource.password=root

  #logging

  logging.level.com.wyj.mapper:debug

  User:

  @Data

  @Entity

  public class User implements Serializable {

  @Id

  @KeySql(useGeneratedKeys = true)

  private Integer id;

  private String name;

  private String sex;

  private Integer age;

  private String address;

  private String phone;

  }

  SpringbootTkmybatisApplication:

  @SpringBootApplication

  @MapperScan("com.wyj.mapper")//tkmybatis的注解

  public class SpringbootTkmybatisApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringbootTkmybatisApplication.class, args);

  }

  }

springboot整合tkmybatis的更多相关文章

  1. spring-boot整合mybatis(1)

    sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...

  2. SpringBoot整合Mybatis之项目结构、数据源

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  3. springboot整合mq接收消息队列

    继上篇springboot整合mq发送消息队列 本篇主要在上篇基础上进行activiemq消息队列的接收springboot整合mq发送消息队列 第一步:新建marven项目,配置pom文件 < ...

  4. springboot整合mybaits注解开发

    springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...

  5. SpringBoot整合Redis、ApachSolr和SpringSession

    SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...

  6. SpringBoot整合ElasticSearch实现多版本的兼容

    前言 在上一篇学习SpringBoot中,整合了Mybatis.Druid和PageHelper并实现了多数据源的操作.本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和Spring ...

  7. SpringBoot整合Kafka和Storm

    前言 本篇文章主要介绍的是SpringBoot整合kafka和storm以及在这过程遇到的一些问题和解决方案. kafka和storm的相关知识 如果你对kafka和storm熟悉的话,这一段可以直接 ...

  8. SpringBoot整合SpringCloud搭建分布式应用

    什么是SpringCloud? SpringCloud是一个分布式的整体解决方案.SpringCloud为开发者提供了在分布式系统中快速构建的工具,使用SpringCloud可以快速的启动服务或构建应 ...

  9. SpringBoot整合RabbitMQ-整合演示

    本系列是学习SpringBoot整合RabbitMQ的练手,包含服务安装,RabbitMQ整合SpringBoot2.x,消息可靠性投递实现等三篇博客. 学习路径:https://www.imooc. ...

随机推荐

  1. win10回收站右键有2个“CCleaner”怎么删除

      win10回收站右键有2个"CCleaner"怎么删除? win10系统安装最新的CCleaner后遇到了这样子的问题:右击回收站有两个关于CCleaner的乱码,卸载CCle ...

  2. pg_escape_string专用于转义数据库敏感字符

    (PHP 4 >= 4.2.0, PHP 5) pg_escape_string — 转义 text/char 类型的字符串 说明 string pg_escape_string ( strin ...

  3. 关于js.map以及css.map

    什么是source map文件. source map文件是js文件压缩后,文件的变量名替换对应.变量所在位置等元信息数据文件,一般这种文件和min.js主文件放在同一个目录下. 比如压缩后原变量是m ...

  4. mysql skip-grant-tables 后要多次重启 和验证登录检查确认密码生效

    mysql  skip-grant-tables 后要多次重启  和验证登录检查确认密码生效

  5. vue-admin-template 切换回中文

    使用vue-admin-template开发项目,使用的是element-ui的控件,但这个框架走的是国际化,是英文版,好吧!快速切换为中文版: 找到main.js 第七行: 替换为: import ...

  6. springboot项目中使用spring-data-Redis对map序列化时报错

    错误信息: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at org.spri ...

  7. pycharm 2019.2 安装包失败

    简介: 最近使用学生账号注册了pycharm,貌似全家桶都可以免费用了,就升级了pycharm到最新版. 但是在使用包管理,安装包的时候出错了 提示没有匹配的版本,下面还提示一个 --trusted- ...

  8. [LeetCode] 271. Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  9. 一文读懂ZooKeeper (转)

    什么是ZooKeeper ZooKeeper 是一个分布式的,开放源码的分布式应用程序协同服务.ZooKeeper 的设计目标是将那些复杂且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集 ...

  10. mysql查看和修改最大连接数

    查看最大连接数 SHOW VARIABLES LIKE '%max_connections%'; 修改最大连接数 ;