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. css3实现左侧固宽,右侧随着屏幕,右侧随着屏幕变化而变化

    A, ----float+calc(css3新属性计算属性)方式 <div class="Father"> <div class="LeftChildr ...

  2. 工具系列 | VScode Remote 远程开发与调试(告别SSH)

    简介 最近VScode发布了远程编程与调试的插件Remote Development,使用这个插件可以在很多情况下代替vim直接远程修改与调试服务器上的代码,同时具备代码高亮与补全功能,就和在本地使用 ...

  3. (6)Flask项目之会员注册页面

    一.添加注册页面的路由 修改app/home/views.py内容,追加注册("/regist/")页面的路由: # coding:utf8 from . import home ...

  4. mysql or条件查询优化

    当使用or的时候是不会用到索引的 explain SELECT * FROM aladdin_resource WHERE state = 1 OR state = 2; 解决办法就是用union替换 ...

  5. [LeetCode] 167. Two Sum II - Input array is sorted 两数和 II - 输入是有序的数组

    Given an array of integers that is already sorted in ascending order, find two numbers such that the ...

  6. java开发异常Exception集锦

    背景:整理开发过程中的异常问题 java.lang.Exception: No tests found matching 一般出现在新导入的工程中.在sts中通过open project的方式导入工程 ...

  7. vscode插件Power Mode

    Power Mode官网 设置里添加 "powermode.enabled": true, "powermode.presets": "flames& ...

  8. Dubbo服务器与普通服务器的区别

    Dubbo是一个阿里巴巴开源出来的一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. 1.什么是分布式服务框架 分布式有两个特点,分别是内聚性和透明性(比如 ...

  9. Java开发笔记(一百二十)AWT文本标签

    前面介绍了AWT窗口及其面板的简单用法,其中展示出来的控件只有按钮一种,还有很多好用好玩的控件有待介绍.首先是文本标签Label,该控件用于显示一段平铺文本,它不花哨也不跳动,完全就是素面朝天的文本字 ...

  10. Fedora30 - Xrdp 远程桌面

    Windows RDP 访问 Fedor 远程桌面需要使用 Xrdp 开源工具. [lipandeng@localhost ~]$ sudo dnf install xrdp [lipandeng@l ...