接着上一节

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. [完美]原生JS获取浏览器版本判断--支持Edge,IE,Chrome,Firefox,Opera,Safari,以及各种使用Chrome和IE混合内核的浏览器

    截至自2017-08-11,支持现世已出的几乎所有PC端浏览器版本判断. 受支持的PC端浏览器列表: Edge IE Chrome Firefox Opera Safari QQ浏览器 360系列浏览 ...

  2. js 星星效果思路

    //星星的效果思路 1.获取需要修改的元素 ul li 跟p 布局 2.给li 加移入事件 更改提示框显示, 3.给li 加移出事件 更改提示框隐藏 4.给li加索引值代表自己的序号 5.在li移入时 ...

  3. ORA-12805: parallel query server died unexpectedly ORA-04030 (sort subheap,sort key) 原因排查与解决方法

    今日,某服务器pga调整为30G,_pga_max_size调整为8G之后(原来是2G,但是one passes语句较多,性能太低),执行出现ORA-12805: parallel query ser ...

  4. 整型 布尔值 字符串 for循环

    1.整型 2.布尔值 3.字符串 4.for循环 1.整型:.python中有长整型, Python3中只有整型 2.布尔值: bool:Ture 真       False 假 数字和布尔值可进行转 ...

  5. 学习类后回顾pickle及collections模块应用场景优化

    1.首先创建一个类,并给出一个对象 class Dog(object): def __init__(self,name,kind,age): self.name=name self.kind=kind ...

  6. zabbix/自动发现规则

      对于zabbix 我们并不陌生 他是开源的监控系统,现在的一部分企业都在用zabbix,今天给大家分享的是企业级监控zabbix的自动发现规则,有了它我们自定义健康的时候根据宏值可以让他自动发现对 ...

  7. python from entry to abandon2

    学习Linux已经有大致两周了,依然感觉到自己仍然在运维的大门外徘徊.于是我想要找到一个在Linux之外的业余方向,可以以作为枯燥基础学习的调节.没过多久我就发现了Python可以说是钦定的选择,它作 ...

  8. C#中get和set

    释一: 属性的访问器包含与获取(读取或计算)或设置(写)属性有关的可执行语句.访问器声明可以包含 get 访问器或 set 访问器,或者两者均包含.声明采用下列形式之一: get {} set {} ...

  9. Pandas 基础(9) - 组合方法 merge

    首先, 还是以天气为例, 准备如下数据: df1 = pd.DataFrame({ 'city': ['newyork', 'chicago', 'orlando'], 'temperature': ...

  10. ceph储存的S3接口实现(支持断点续传)

    最近公司准备接ceph储存,研究了一番,准备用亚马逊的s3接口实现,实现类如下: /** * Title: S3Manager * Description: Ceph储存的s3接口实现,参考文档: * ...