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. 工具系列 | VScode Remote 远程开发与调试(告别SSH)

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

  2. 使用expect快速登录线上机器

    背景: 公司登陆线上服务器一般都要经过跳板机才能登陆,过程比较麻烦,如果要频繁登陆某个机器而且机器名不好记很费劲,使用expect自动登陆会方便很多 实现: 使用expect脚本自动登陆: #!/us ...

  3. MUD游戏开发教程视频

    MUD游戏开发教程视频 https://space.bilibili.com/476328540/channel/detail?cid=91187

  4. java:网络编程(UDP (DatagramSocket和DatagramPacket)正则表达式)

    java:网络编程(UDP (DatagramSocket和DatagramPacket)正则表达式) * TCP* 特点:面向连接,点对点的通信,效率较低,但安全可靠* UDP:用户数据报协议,类似 ...

  5. mongodb 切换wiredtiger

    1.由于最近用到mongodb但查询时前十分左右,用压力测试不太稳定,所以换成第三方引擎试试,但效果还是一样. 具说第三方引擎比较给力,但在使用没有发现.现将mongodb切换wiredtiger引擎 ...

  6. nvm安装、解决nvm command not found问题、卸载

    安装 nvm是node的包版本管理工具,github地址如下:nvm 安装命令 1 curl -o- https://raw.githubusercontent.com/creationix/nvm/ ...

  7. java的byte[]与String相互转换

    String转byte[] byte[] sInput = new byte[0]; try { // 可以指定编码,默认也只UTF-8 sInput = "这是内容".getBy ...

  8. ES(ElasticSearch)文档的表现形式以及增删改查

    1. ES中的文档 ES是面向文档(document oriented)的,这意味着它可以存储整个对象或文档(document).然而它不仅仅是存储,还会索引(index)每个文档的内容使之可以被搜索 ...

  9. 自定义 Word 默认的 Normal.dotm 模板、更改 Word 默认字体、更改 Word 默认样式(16)

    1. 引言 以Office 2016为例. 有没有遇见这样的问题: 每次新建一个 Word 空白文档打开后字体默认是等线,段落默认是单倍行距,默认标题也不是自己想要的样式,等一系列问题.每次打开都要调 ...

  10. int main(int argc, char *argv[])解释

    int main(int argc, char *argv[]) 详解: #include <stdio.h> int main(int argc, char *argv[]) { int ...