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> ...
随机推荐
- 死磕nginx系列-nginx日志配置
nginx access日志配置 access_log日志配置 access_log用来定义日志级别,日志位置.语法如下: 日志级别: debug > info > notice > ...
- 在 Laravel 5 中集成七牛云存储实现云存储功能
本扩展包基于https://github.com/qiniu/php-sdk开发,是七牛云储存 Laravel 5 Storage版,通过本扩展包可以在Laravel 5中集成七牛云存储功能. 1 ...
- Python第三方模块--requests简单使用
1.requests简介 requests是什么?python语言编写的,基于urllib的第三方模块 与urllib有什么关系?urllib是python的内置模块,比urllib更加简洁和方便使用 ...
- SpringBoot实用技巧札记
目录 如何手工设置SpringBoot内嵌的Tomcat启动端口号(port) 如何解决Eclipse.Properties中文乱码的问题 如何手工设置SpringBoot内嵌的Tomcat启动端口号 ...
- hadoop集群部署配置补充
/etc/hosts192.168.153.147 Hadoop-host192.168.153.146 Hadoopnode1 192.168.153.145 Hadoopnode2::1 loca ...
- openJDK环境搭建编译(fedora)
1.安装VMware VMware-workstation-full-10.0.7-2844087.exe 破解码:HY06L-F334P-9Z6H9-6R2XM-23C6J 安装完成之后, ...
- 纯css实现弹窗左右垂直居中效果
1.HTML <div class="container"> <div class="dialog"> <div class=&q ...
- MVC 在action方法中获取当前action的控制器名和action名
如何在某个action方法中获取它所在的控制器和action名称呢. string controllerName = Request.RequestContext.RouteData.Values[& ...
- 【转】python直接运行tcl脚本
python中调用tcl是通过加载TkInter来实现的. from Tkinter import Tcl tcl = Tcl() tcl.eval('source tu.tcl') tcl.eval ...
- 20155207 《网络对抗技术》EXP3 免杀原理与实践
20155207 <网络对抗技术>EXP3 免杀原理与实践 基础问题回答 杀软是如何检测出恶意代码的? - 根据特征码进行检测(静态) - 启发式(模糊特征点.行为 ) - 根据行为进行检 ...