SpringBoot+SpringCloud+vue+Element开发项目——集成MyBatis框架
添加mybatis-spring-boot-starter依赖
pox.xml
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
添加mybatis配置类
新建config包 MybatisConfig.java
@Configuration
@MapperScan("com.read.mdh.*.dao") //扫描dao包
public class MybatisConfig { @Autowired
private DataSource dataSource; @Bean
public SqlSessionFactory sqlSessionFactory() throws Exception{
SqlSessionFactoryBean sqlSessionFactoryBean=new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setTypeAliasesPackage("com.read.mdh.*.model"); //扫描model
PathMatchingResourcePatternResolver resolver=new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:**/sqlmap/*.xml"));
return sqlSessionFactoryBean.getObject();
}
}
添加数据源配置
application.yml
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mdh?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8
username: root
password: root
修改启动类
MdhApplication.java
@SpringBootApplication(scanBasePackages = {"com.read.mdh"})
@EnableSwagger2
public class MdhApplication {
public static void main(String[] args){
SpringApplication.run(MdhApplication.class,args);
}
}
http://www.mybatis.org/generator/index.html生产Mybatis模板
https://blog.csdn.net/testcs_dn/article/details/77881776
http://mp.baomidou.com/#/quick-start
Mapper中添加findAll方法
SysUserMappper.java
@Mapper
public interface SysUserMapper {
int deleteByPrimaryKey(Long id); int insert(SysUser record); int insertSelective(SysUser record); SysUser selectByPrimaryKey(Long id); int updateByPrimaryKeySelective(SysUser record); int updateByPrimaryKey(SysUser record); /**
* 查询全部
* @return
*/
List<SysUser> findAll();
}
映射文件添加查询方法
SysUserMapper.xml
<select id="findAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_user
</select>
service添加findAll方法
SysUserService.java
public interface SysUserService {
/**
* 查找所有用户
* @return
*/
List<SysUser> findAll();
}
service添加实现类调用SysUserMapper方法完成查询操作
SysUserServiceImpl.java
@Service
public class SysUserServiceImpl implements SysUserService { @Autowired
private SysUserMapper sysUserMapper; @Override
public List<SysUser> findAll() {
return sysUserMapper.findAll();
}
}
编写用户管理RESTful接口,返回JSON数据格式,提供外部调用
SysUserController.java
@RestController
@RequestMapping("user")
public class SysUserController { @Autowired
private SysUserService sysUserService; @GetMapping(value ="findAll")
public Object find(){
return sysUserService.findAll();
}
}
配置打包资源
修改pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!--打包时复制mybatis的映射文件-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/sqlmap/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
SpringBoot+SpringCloud+vue+Element开发项目——集成MyBatis框架的更多相关文章
- SpringBoot+SpringCloud+vue+Element开发项目——集成Druid数据源
添加依赖 pom.xml <!--druid--> <dependency> <groupId>com.alibaba</groupId> <ar ...
- SpringBoot+SpringCloud+vue+Element开发项目——集成Swagger文档
在pom.xml文件中添加Maven依赖 <!--swagger--> <dependency> <groupId>io.springfox</groupId ...
- SpringBoot+SpringCloud+vue+Element开发项目——搭建开发环境
1.新建一个项目
- SpringBoot+SpringCloud+vue+Element开发项目——数据库设计
1.用户表(sys_user) CREATE TABLE `sys_user` ( `id` ) NOT NULL AUTO_INCREMENT COMMENT '编号', `name` ) NOT ...
- 基于【 springBoot +springCloud+vue 项目】一 || 项目架构简介
一.前言 基于前期学习以及工作经验积累,持续更新基于springboot+springcloud+vue的demo项目.
- 在Vue&Element前端项目中,对于字典列表的显示处理
在很多项目开发中,我们为了使用方便,一般都会封装一些自定义组件来简化界面的显示处理,例如参照字典的下拉列表显示,是我们项目中经常用到的功能之一,本篇随笔介绍在Vue&Element前端项目中如 ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目
一:创建maven web项目er
- 在Vue&Element前端项目中,使用FastReport + pdf.js生成并展示自定义报表
在我的<FastReport报表随笔>介绍过各种FastReport的报表设计和使用,FastReport报表可以弹性的独立设计格式,并可以在Asp.net网站上.Winform端上使用, ...
- flink 流式处理中如何集成mybatis框架
flink 中自身虽然实现了大量的connectors,如下图所示,也实现了jdbc的connector,可以通过jdbc 去操作数据库,但是flink-jdbc包中对数据库的操作是以ROW来操作并且 ...
随机推荐
- Python之Lambda与三元运算
Python之Lambda与三元运算 Lambda 运算 概念:是指一类无需定义标识符(函数名)的函数或者子程序.特点:匿名函数不使用def定义函数,使用lambda来创建匿名函数1.lambda只是 ...
- MongoDB笔记: 常见问题
系统配置 设置ulimit MongoDB的文件机制 每个Collection会单独创建一个数据文件(collection-xxxxxx.wt) 每个索引会单独创建一个文件(index-xxxxxx. ...
- Eclipse创建Maven父子项目
Eclipse创建Maven父子项目 - 木头若愚 - CSDN博客https://blog.csdn.net/jay_1989/article/details/53906995 创建maven项目是 ...
- [转]eclipse中explorer显示方式
原文地址:https://www.cnblogs.com/gne-hwz/p/7590451.html 不知道是不是上面的描述.做个记录 project explorer 项目资源管理器 这个要打开代 ...
- 【winform】主窗体多线程给子窗体传值
1.主窗体多线程给子窗体传值 解决方案:主要使用委托,因为会出现跨线程错误 主窗体 public FormMain() { InitializeComponent(); //background th ...
- vue---使用Class
在用vue-cli开发项目的时候,很多时候会用到类.具体的使用方法: config.js(使用类,还可以定义构造函数) class config { /** * 构造函数 * @param {stri ...
- Nginx 配置 HTTPS SSL
配置文件如下:[可以在阿里云上申请免费证书] #user nobody; worker_processes 1; events { worker_connections 1024; } http { ...
- [LeetCode] 312. Burst Balloons 爆气球
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...
- jquery on绑定事件叠加解决方法
jquery on绑定事件叠加解决方法 代码如下 <pre> $('.maoqiu').each(function () { var is_bind = $(this).attr('is_ ...
- ll问题
不能直接用ll 要用__int64 (64和int 之间无空格) #define ll __int64