springboot+mybatis结合使用
springboot+mybatis结合使用与普通的ssm配置差别不大,但是少了很多的配置,如spring.xml web.xml, 给程序员减轻了很多负担
首先创建带有mybatis框架的项目
*.xml配置与ssm无异
配置application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/m1
spring.datasource.username=root
spring.datasource.password=mlh123456
mybatis.type-aliases-package=com.test.entity
mybatis.mapper-locations=classpath:mapper/*.xml
entity层
package com.test.entity; /**
* Created by MY on 2017/8/15.
*/
public class Girls {
private Integer id;
private String cup_size;
private Integer age; public Girls(Integer id, String cup_Size, Integer age) {
this.id = id;
this.cup_size = cup_size;
this.age = age;
} public String getCup_size() {
return cup_size;
} public void setCup_size(String cup_Size) {
this.cup_size = cup_Size;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public Girls() { }
}
dao层 **类名注解** @Mapper该注解只表示与*.xml的映射,不能表示将该对象交给spring管理
package com.test.dao; import com.test.entity.Girls;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository; import java.util.List; /**
* Created by MY on 2017/8/15.
*/
@Mapper
@Repository
public interface GirlsDao {
List<Girls> findAllGirls();
}
controller层
package com.test.contoller; import com.test.dao.GirlsDao;
import com.test.entity.Girls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import java.util.List; /**
* Created by MY on 2017/8/15.
*/
@Controller
public class FirstController { @Autowired
private GirlsDao gd; @RequestMapping("first")
public String first(){
return "abc";
} @ResponseBody
@RequestMapping("find.do")
public List<Girls> findAllGirls(){
return gd.findAllGirls();
} }
springboot+mybatis结合使用的更多相关文章
- 第五章 springboot + mybatis(转载)
本编博客转发自:http://www.cnblogs.com/java-zhao/p/5350021.html springboot集成了springJDBC与JPA,但是没有集成mybatis,所以 ...
- 第九章 springboot + mybatis + 多数据源 (AOP实现)
在第八章 springboot + mybatis + 多数据源代码的基础上,做两点修改 1.ShopDao package com.xxx.firstboot.dao; import org.spr ...
- 第五章 springboot + mybatis
springboot集成了springJDBC与JPA,但是没有集成mybatis,所以想要使用mybatis就要自己去集成.集成方式相当简单. 1.项目结构 2.pom.xml <!-- 与数 ...
- 基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建
基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建 前言 最近做回后台开发,重新抓起以前学过的SSM(Spring+Sp ...
- Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦
个人博客 对于技术人员来说,拥有自己的个人博客应该是一件令人向往的事情,可以记录和分享自己的观点,想到这件事就觉得有意思,但是刚开始写博客的时候脑海中是没有搭建个人博客这一想法的,因为刚起步的时候连我 ...
- springboot mybatis 事务管理
本文主要讲述springboot提供的声明式的事务管理机制. 一.一些概念 声明式的事务管理是基于AOP的,在springboot中可以通过@Transactional注解的方式获得支持,这种方式的优 ...
- SpringBoot+Mybatis+Freemark 最简单的例子
springboot-sample 实现最简单的 SpringBoot + Mybatis + Freemarker 网页增删改查功能,适合新接触 Java 和 SpringBoot 的同学参考 代码 ...
- springboot + mybatis 前后端分离项目的搭建 适合在学习中的大学生
人生如戏,戏子多半掉泪! 我是一名大四学生,刚进入一家软件件公司实习,虽说在大学中做过好多个实训项目,都是自己完成,没有组员的配合.但是在这一个月的实习中,我从以前别人教走到了现在的自学,成长很多. ...
- springboot+mybatis+redis实现分布式缓存
大家都知道springboot项目都是微服务部署,A服务和B服务分开部署,那么它们如何更新或者获取共有模块的缓存数据,或者给A服务做分布式集群负载,如何确保A服务的所有集群都能同步公共模块的缓存数据, ...
- Java逆向工程SpringBoot + Mybatis Generator + MySQL
Java逆向工程SpringBoot+ Mybatis Generator + MySQL Meven pop.xml文件添加引用: <dependency> <groupId> ...
随机推荐
- CSP vs Actor Go vs Erlang
源于从Erlang到Go的一些思维碰撞,就像当初从C++到Erlang一样,整理下来记于此. Actor Actor模型,又叫参与者模型,其”一切皆参与者(actor)”的理念与面向对象编程的“一切皆 ...
- Swift 并行编程现状和展望 - async/await 和参与者模式
这篇文章不是针对当前版本 Swift 3 的,而是对预计于 2018 年发布的 Swift 5 的一些特性的猜想.如果两年后我还记得这篇文章,可能会回来更新一波.在此之前,请当作一篇对现代语言并行编程 ...
- sql 一个表的字段更新至另一个字段的方法
update Lc_Taxs set TaxMember = convert(int,Lc_Taxs2.TaxNo) from Lc_Taxs a,(select * from Lc_Taxs ) ...
- 基于TP5使用Websocket框架之GatewayWorker开发电商平台买家与卖家实时通讯
https://www.cnblogs.com/wt645631686/p/7366924.html 前段时间公司提了一个新的需求,在商品的详情页要实现站内买家和商品卖家实时通讯的功能以方便沟通促成交 ...
- 随手练——DFS小练
1. 单词接龙 https://www.luogu.org/problemnew/show/P1019 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头 ...
- “System.Reflection.AmbiguousMatchException”类型的异常在 mscorlib.dll 中发生
错误提示: “System.Reflection.AmbiguousMatchException”类型的异常在 mscorlib.dll 中发生,但未在用户代码中进行处理. 发现不明确的匹配. 问题原 ...
- 【Nodejs】Browsersync同步浏览器测试
说明文档:http://www.browsersync.cn/docs/ 安装命令: ①全局安装 npm install -g browser-sync ②局部/本地安装 npm install br ...
- c# thread pause example
some times we need pause thread to do some additional job: c# thread pause example as below: 1. crea ...
- adb连接手机的两种方式
adb连接手机进行调试有两种方式,一种使用USB线,一种使用无线WiFi. 第一种 使用USB线连接 1. 在手机上启用USB调试 2. CMD窗口输入adb devices,此时可以看到自己的设备 ...
- libgdx学习记录11——平铺地图TiledMap
地图对于游戏场景十分重要,很多游戏都需要对地图进行编辑,可使用TileMap进行编辑并生成对应的tmx格式地图文件. 编辑好后,可通过TmxMapLoader来读取地图文件.可通过一个正交相机Otho ...