接着上一节

1.第一步:在pom文件中添加

 <!--   MyBatis  -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

2.第二步:将userMapper类,改成下面这样

package com.oda.springboot.dao;

import com.oda.springboot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository; import java.util.List; //JPA的
/*
public interface UserMapper extends JpaRepository<User,Integer> {
}
*/
public interface UserMapper{
@Select("select * from user")
public List<User> findUser();
}

3.第三步:将UserService类改成下面这样

package com.oda.springboot.service;

import com.oda.springboot.bean.User;
import com.oda.springboot.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import javax.annotation.Resource;
import java.util.List; @Service
public class UserService {
@Resource
private UserMapper userMapper; //JPA的
/*public List<User> users() {
return userMapper.findAll();
}*/ public List<User> users(){
return userMapper.findUser();
}
}

4.第四步:将SpringbootApplication类改成下面这样

package com.oda.springboot;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; @SpringBootApplication
@MapperScan("com.oda.springboot.dao")
public class SpringbootApplication {
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}

启动,访问http://localhost:8080/zm/users

极简配置(就是sql用xml文件写)

5.第五步:在resources包下新建mapper包,在其下新建userMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.oda.springboot.dao.UserMapper">
<select id="findUser" resultType="com.oda.springboot.bean.User">
select *
from user
</select>
</mapper>

6.第六步:在application.yml中添加

mybatis:
mapper-locations: classpath:mapper/*.xml

启动,访问http://localhost:8080/zm/users

SpringBoot(四)thymeleaf+MyBatis+MySql的更多相关文章

  1. SpringBoot (四) - 整合Mybatis,逆向工程,JPA

    1.SpringBoot整合MyBatis 1.1 application.yml # 数据源配置 spring: datasource: driver-class-name: com.mysql.c ...

  2. 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程

    工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...

  3. Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)

    当任何时候觉你得难受了,其实你的大脑是在进化,当任何时候你觉得轻松,其实都在使用以前的坏习惯. 通过前面的学习,你可能大致了解了Quartz,本篇博文为你打开学习SSMM+Quartz的旅程!欢迎上车 ...

  4. Springboot+Mybatis+MySQL实例练习时踩坑记录

    最近刚开始学习后端,直接让上手学习Springboot+Mybatis+MySQL对CRUD的实例,虽然实例不难,但是上面的三个知识我都不懂,就有点为难我了 所以经常遇到一个点卡自己很久的情况,这里列 ...

  5. Springboot集成mybatis(mysql),mail,mongodb,cassandra,scheduler,redis,kafka,shiro,websocket

    https://blog.csdn.net/a123demi/article/details/78234023  : Springboot集成mybatis(mysql),mail,mongodb,c ...

  6. springboot成神之——springboot+mybatis+mysql搭建项目简明demo

    springboot+mybatis+mysql搭建项目简明demo 项目所需目录结构 pom.xml文件配置 application.properties文件配置 MyApplication.jav ...

  7. (转) Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)

    http://blog.csdn.net/u010648555/article/details/60767633 当任何时候觉你得难受了,其实你的大脑是在进化,当任何时候你觉得轻松,其实都在使用以前的 ...

  8. SpringBoot+MyBatis+Mysql 6.X 版本日期型数据获,时间错乱,jason序列化时间相差8小时问题

    新项目是用的springboot+mybatis+mysql 6.0.6版本的驱动包来搭建的,在使用的过程中遇到以下2个问题 从mysql取的的数据日期时间,与真实的时间往后错乱了14个小时. spr ...

  9. 从 0 使用 SpringBoot MyBatis MySQL Redis Elasticsearch打造企业级 RESTful API 项目实战

    大家好!这是一门付费视频课程.新课优惠价 699 元,折合每小时 9 元左右,需要朋友的联系爱学啊客服 QQ:3469271680:我们每课程是明码标价的,因为如果售价为现在的 2 倍,然后打 5 折 ...

随机推荐

  1. java 原码反码及补码 总结

    参考: http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html http://blog.csdn.net/lius ...

  2. 【Entity Framework】Revert the database to specified migration.

    本文涉及的相关问题,如果你的问题或需求有与下面所述相似之处,请阅读本文 [Entity Framework] Revert the database to specified migration. [ ...

  3. 面试必问的SpringCloud实现原理图

    引言 面试中面试官喜欢问组件的实现原理,尤其是常用技术,我们平时使用了SpringCloud还需要了解它的实现原理,这样不仅起到举一反三的作用,还能帮助轻松应对各种问题及有针对的进行扩展. 以下是 课 ...

  4. 字体转换网站——Font Squirrel

    转载自:http://www.5imoban.net/jiaocheng/CSS3_HTML5/2016/0714/1735.html html5之前,只要稍微特殊点的字体,都必须做成图片,以免客户端 ...

  5. Apache Solr入门教程(初学者之旅)

    Apache Solr入门教程(初学者之旅) 写在前面:本文涉及solr入门的各方面,建议边思考边实践,相信能帮助你对solr有个清晰全面的了解并能简单实用. 在Apache Solr初学者教程的这个 ...

  6. [python]python2与python3版本的区别

    python2和python3的区别 区别: print函数 整数相除 Unicode 异常处理 xrange map函数 不支持has_key print函数: Python 2: print是语句 ...

  7. URL URI

    URL 是统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及浏览器应该怎么处理 ...

  8. python实现以application/json格式为请求体的http post请求

    接口传递数据格式类型为json格式,如下图抓包查看 Python实现脚本请求接口并以中文打印接口返回的数据 import json import requests url = "https: ...

  9. 『计算机视觉』R-FCN:Object Detection via Region-based Fully Convolutional Networks

    一.网络介绍 参考文章:R-FCN详解 论文地址:Object Detection via Region-based Fully Convolutional Networks R-FCN是Faster ...

  10. Matlab:高阶常微分三种边界条件的特殊解法(中心差分法,高精度导数边界处理)

    函数文件1: function b=F(f,x0,h,N) % b(1,1)=x0(1)-h*x0(2)-u(1); % b(2,1)=x0(2)+h*x0(1)^2-u(2)-h*f; b=zero ...