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结合使用的更多相关文章

  1. 第五章 springboot + mybatis(转载)

    本编博客转发自:http://www.cnblogs.com/java-zhao/p/5350021.html springboot集成了springJDBC与JPA,但是没有集成mybatis,所以 ...

  2. 第九章 springboot + mybatis + 多数据源 (AOP实现)

    在第八章 springboot + mybatis + 多数据源代码的基础上,做两点修改 1.ShopDao package com.xxx.firstboot.dao; import org.spr ...

  3. 第五章 springboot + mybatis

    springboot集成了springJDBC与JPA,但是没有集成mybatis,所以想要使用mybatis就要自己去集成.集成方式相当简单. 1.项目结构 2.pom.xml <!-- 与数 ...

  4. 基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建

    基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建 前言 最近做回后台开发,重新抓起以前学过的SSM(Spring+Sp ...

  5. Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦

    个人博客 对于技术人员来说,拥有自己的个人博客应该是一件令人向往的事情,可以记录和分享自己的观点,想到这件事就觉得有意思,但是刚开始写博客的时候脑海中是没有搭建个人博客这一想法的,因为刚起步的时候连我 ...

  6. springboot mybatis 事务管理

    本文主要讲述springboot提供的声明式的事务管理机制. 一.一些概念 声明式的事务管理是基于AOP的,在springboot中可以通过@Transactional注解的方式获得支持,这种方式的优 ...

  7. SpringBoot+Mybatis+Freemark 最简单的例子

    springboot-sample 实现最简单的 SpringBoot + Mybatis + Freemarker 网页增删改查功能,适合新接触 Java 和 SpringBoot 的同学参考 代码 ...

  8. springboot + mybatis 前后端分离项目的搭建 适合在学习中的大学生

    人生如戏,戏子多半掉泪! 我是一名大四学生,刚进入一家软件件公司实习,虽说在大学中做过好多个实训项目,都是自己完成,没有组员的配合.但是在这一个月的实习中,我从以前别人教走到了现在的自学,成长很多. ...

  9. springboot+mybatis+redis实现分布式缓存

    大家都知道springboot项目都是微服务部署,A服务和B服务分开部署,那么它们如何更新或者获取共有模块的缓存数据,或者给A服务做分布式集群负载,如何确保A服务的所有集群都能同步公共模块的缓存数据, ...

  10. Java逆向工程SpringBoot + Mybatis Generator + MySQL

    Java逆向工程SpringBoot+ Mybatis Generator + MySQL Meven pop.xml文件添加引用: <dependency> <groupId> ...

随机推荐

  1. 构造方法,this关键字,static关键字,封装

    1.构造方法 定义:构造方法是指实例化对象的方法 语法:[修饰符]  类名(参数){    } 根据有无参数分为有参构造和无参构造 1)有参构造 语法:[修饰符]  类名(type 实例变量,int ...

  2. 接收键盘输入的字符串,用FileWirter类将字符串写入文件,用FileReader类读出文件内容显示在屏幕上

    public class SY63 { public static void main(String[] args) throws Exception { System.out.print(" ...

  3. 前端性能优化:Add Expires headers

    前端性能优化:Add Expires headers Expires headers 是什么? Expires headers:直接翻译是过期头.Expires headers 告诉浏览器是否应该从服 ...

  4. day05-列表类型

    列表类型: 用途:存放多个值,根据索引. 定义方式:在[]内用逗号分隔开多个任意类型的值 L1 = list[{a:1,b:2,c:3}] 输出的为字典的key值 常用操作+内置方法 1.按索引取值: ...

  5. 在mvc视图中实现rdlc报表展示

    需求:在view视图页面中嵌入rdlc报表,rdlc的xml为动态传入的xml字符串.本项目是基于abp框架 可能出现问题: 1.rdlc报表是由asp.net的服务器控件ReportViewer来支 ...

  6. excel实用技巧——vlookup函数

    1.VLOOKUP函数的套路 VLOOKUP(要找谁,在哪儿找,返回第几列的内容,精确找还是近似找) 最后一个参数: 如果为0或FASLE,用精确匹配方式,而且支持无序查找: 如果为TRUE或被省略, ...

  7. CISCN 应用环境相关指令备忘录

    1 - 关于Python环境的 使用Anaconda2管理Python环境 1.1 - 安装 官网下载安装包下载. 1.2 - 创建Python环境 localhost:template mac$ c ...

  8. cocos2d-x学习记录2——CCAction动作

    CCAction能够使CCNode运动起来,能够呈现出多种多样的动作.这些动作能够改变其运动方向.形状.大小.旋转等. 同时,还可利用CCCallFunc.CCCallFuncN.CCCallFunc ...

  9. HashMap 源码解析(一)之使用、构造以及计算容量

    目录 简介 集合和映射 HashMap 特点 使用 构造 相关属性 构造方法 tableSizeFor 函数 一般的算法(效率低, 不值得借鉴) tableSizeFor 函数算法 效率比较 tabl ...

  10. 算法(JAVA)----两道小小课后题

    LZ最近翻了翻JAVA版的数据结构与算法,无聊之下将书中的课后题一一给做了一遍,在此给出书中课后题的答案(非标准答案,是LZ的答案,猿友们可以贡献出自己更快的算法). 1.编写一个程序解决选择问题.令 ...