SpringBoot(四)thymeleaf+MyBatis+MySql
接着上一节
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的更多相关文章
- SpringBoot (四) - 整合Mybatis,逆向工程,JPA
1.SpringBoot整合MyBatis 1.1 application.yml # 数据源配置 spring: datasource: driver-class-name: com.mysql.c ...
- 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程
工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...
- Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)
当任何时候觉你得难受了,其实你的大脑是在进化,当任何时候你觉得轻松,其实都在使用以前的坏习惯. 通过前面的学习,你可能大致了解了Quartz,本篇博文为你打开学习SSMM+Quartz的旅程!欢迎上车 ...
- Springboot+Mybatis+MySQL实例练习时踩坑记录
最近刚开始学习后端,直接让上手学习Springboot+Mybatis+MySQL对CRUD的实例,虽然实例不难,但是上面的三个知识我都不懂,就有点为难我了 所以经常遇到一个点卡自己很久的情况,这里列 ...
- 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 ...
- springboot成神之——springboot+mybatis+mysql搭建项目简明demo
springboot+mybatis+mysql搭建项目简明demo 项目所需目录结构 pom.xml文件配置 application.properties文件配置 MyApplication.jav ...
- (转) Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)
http://blog.csdn.net/u010648555/article/details/60767633 当任何时候觉你得难受了,其实你的大脑是在进化,当任何时候你觉得轻松,其实都在使用以前的 ...
- SpringBoot+MyBatis+Mysql 6.X 版本日期型数据获,时间错乱,jason序列化时间相差8小时问题
新项目是用的springboot+mybatis+mysql 6.0.6版本的驱动包来搭建的,在使用的过程中遇到以下2个问题 从mysql取的的数据日期时间,与真实的时间往后错乱了14个小时. spr ...
- 从 0 使用 SpringBoot MyBatis MySQL Redis Elasticsearch打造企业级 RESTful API 项目实战
大家好!这是一门付费视频课程.新课优惠价 699 元,折合每小时 9 元左右,需要朋友的联系爱学啊客服 QQ:3469271680:我们每课程是明码标价的,因为如果售价为现在的 2 倍,然后打 5 折 ...
随机推荐
- week_one-python基础 基本语法、流程控制
金角大王的紫金葫芦,python开发环境介绍链接:http://list.youku.com/albumlist/show/id_28961509.html # Author:larlly pytho ...
- <转>jmeter(十八)关联之XPath Extractor
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...
- Html select、option、optgroup 标签
Html select 标签 </body> </html> <!-- select外部下拉选择框.name="xxx"标识后端获取名称 --> ...
- 5.Dubbo原理解析-代理之Javassist字节码技术生成代理 (转)
转载自 斩秋的专栏 http://blog.csdn.net/quhongwei_zhanqiu/article/details/41597219 JavassistProxyFactory:利用 ...
- 结合iconworkshop,创建ribbon界面
mfc实现的程序中,ribbon界面是主流,比较适合测量类项目.几个修改图标的小技巧: 1.现有的bmp,可以直接修改 在好几个地方,已经将IDB_*和显示效果对接清楚了,直接修改这里的bmp,就可以 ...
- SIP 编解码器
编解码器,编码器 - 解码器的简称,做两个基本操作 - 首先,它将模拟语音信号转换为其等效数字形式,以便可以容易地发送. 此后,它将压缩的数字信号转换回其原始模拟形式,以便可以重放. 市场上有许多编解 ...
- .Net 读取配置文件 xml
直接解析XML文件 1.System.Xml.Linq命名空间下提供可以使用linq查询的类,使用linq to xml读取也很方便. 2.还可以使用System.Xml.Serialization类 ...
- 使用windeployqt工具来进行Qt的打包发布
https://blog.csdn.net/sinat_36264666/article/details/73305712
- 【Luogu P2664】树上游戏
Problem Description \(lrb\) 有一棵树,树的每个节点有个颜色.给一个长度为 \(n\) 的颜色序列,定义 \(s(i,j)\) 为 \(i\) 到 \(j\) 的颜色数量.以 ...
- 软工实践练习一 关于GIT的使用
在Github上的操作部分: 1.在Github网站上进行注册.https://github.com/ 2.创建小组Organization. 3.将代码库https://github.com/sef ...