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> ...
随机推荐
- elk平台定制化查询规则
一.查询某IP在某时间内TOP10的请求 步骤: 点击“Visualize”选项卡 创建“Data table” 点击“From a new search” 下拉选择“F5-access” 在“buc ...
- OpenCV——边缘检测入门、Canny边缘检测
边缘检测的一般步骤: 最优边缘检测的三个评价标准: 低错误率:表示出尽可能多的实际边缘,同时尽可能地减少噪声产生的误报: 高定位性:标识出的边缘要与图像实际边缘尽可能接近: 最小响应:图像中的边缘只能 ...
- 静态工厂方法和实例工厂方法及普通的bean
容纳你的bean bean工厂:最简单的容器,提供了基础的依赖注入支持.创建各种类型的Bean. 应用上下文(ApplicationContext):建立在bean工厂基础之上,提供系统架构服务. ...
- lvs 最常用算法 + tcpdump vrrp 抓包
1.SH: source hash, 源地址散列. 将请求的目标IP地址换成请求的源IP地址:实现session保持的机制:将来自于同一个IP的请求始终调度至同一RS: 源地址散列调度算法正好与目标地 ...
- DB2创建function(一)
案例一:根据传入的值返回一个满足条件的值.适用于查询的字段(经过较复杂逻辑得出) CREATE FUNCTION "FAS"."GET_ALL_NAME" ( ...
- Codeforces round 1106
Div 2 536 题目链接 我还是太菜了.jpg E 傻逼DP直接做 我居然调了1.5h 我真的是太菜了.jpg 堆+扫描线直接维护每个位置的贪心结果 然后要么使用干扰 要么就接受贪心的结果 #in ...
- THUSC 2017 D1T2 杜老师
这是个非常有趣的数学题啦... 其实大概推一推式子就能得到一个信息,就是答案一定是$2$的整数次幂,并且其实答案就是$2^{R-L+1-sum}$,其中$sum$表示有多少个数不能用$L-i-1$的数 ...
- InkCanvas控件的使用
原文:InkCanvas控件的使用 ==>InkCanvas设置位置跟Canvas一样.通过InkCanvas.Top之类的设置,需要设置的属性有EditingMode,来自于InkCanvas ...
- 3、class文件加载过程
1.加载2.链接(检验/准备/解析) 1/检验过程:检验class的数据格式.2/准备过程:创建静态域,并将这些域设为默认值.3/解析过程:在一个Java类中会包含对其它.类或接口的形式引用,包括它的 ...
- RHEL6 最小化系统 编译安装部署zabbix (mysql)
RHEL6 最小化系统 编译安装部署zabbix (mysql)官方说明详细见:https://www.zabbix.com/documentation/4.0/manual/installation ...