博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot集成MyBatis
阅读量:4102 次
发布时间:2019-05-25

本文共 2662 字,大约阅读时间需要 8 分钟。

pom.xml中添加依赖:

4.0.0
cn.et
SpringBoot_MyBatis
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
1.5.9.RELEASE
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.1
org.apache.tomcat.embed
tomcat-embed-jasper
org.springframework.boot
spring-boot-starter-data-jpa
mysql
mysql-connector-java
runtime
com.alibaba
druid
1.1.5

application.properties中增加配置:

#配置数据库四要素spring.datasource.url=jdbc:mysql://localhost/deskspring.datasource.username=rootspring.datasource.password=123456spring.datasource.driver-class-name=com.mysql.jdbc.Driver#指定数据源spring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.datasource.filters=stat,configspring.jpa.show-sql=true#端口server.port=80#项目上下文server.context-path=/sbm spring.devtools.restart.enabled=true

启动类

package cn.et;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class SpringBootTest {		public static void main(String[] args) {		SpringApplication.run(SpringBootTest.class, args);	}}

controller控制层

package cn.et.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import cn.et.Dept;import cn.et.dao.SpringBootMapper;@RestControllerpublic class SpringBootController {	@Autowired	SpringBootMapper mapper;		@RequestMapping("/queryDept")	public List
query() { return mapper.queryDept(); }}

Dao层,一个@Mapper注解就搞定了

package cn.et.dao;import java.util.List;import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Select;import cn.et.Dept;@Mapperpublic interface SpringBootMapper {		@Select("select * from dept")	public List
queryDept(); }

转载地址:http://cnzsi.baihongyu.com/

你可能感兴趣的文章
程序员之神
查看>>
4 岁小女孩给 Linux 内核贡献提交
查看>>
推荐几个私藏很久的技术公众号给大家
查看>>
王垠受邀面试阿里 P9,被 P10 面跪后网上怒发文,惨打 325 的 P10 赵海平回应了!...
查看>>
Python 趣味打怪:147 段简单代码助你从入门到大师
查看>>
卧槽!小姐姐用动画图解 Git 命令,这也太秀了吧?!
查看>>
厉害了!Python 编辑器界的神器 Jupyter ,推出官方可视化 Debug 工具!
查看>>
卧槽!Java 虚拟机竟然还有这些性能调优技巧...
查看>>
听说玩这些游戏能提升编程能力?
查看>>
7 年工作经验,面试官竟然还让我写算法题???
查看>>
被 Zoom 逼疯的歪果仁,造出了视频会议机器人,同事已笑疯丨开源
查看>>
上古语言从入门到精通:COBOL 教程登上 GitHub 热榜
查看>>
再见,Eclipse...
查看>>
如果你还不了解 RTC,那我强烈建议你看看这个!
查看>>
沙雕程序员在无聊的时候,都搞出了哪些好玩的小玩意...
查看>>
程序员用 AI 修复百年前的老北京视频后,火了!
查看>>
漫话:为什么你下载小电影的时候进度总是卡在 99% 就不动了?
查看>>
我去!原来大神都是这样玩转「多线程与高并发」的...
查看>>
当你无聊时,可以玩玩 GitHub 上这个开源项目...
查看>>
B 站爆红的数学视频,竟是用这个 Python 开源项目做的!
查看>>