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来操作并且 ...
随机推荐
- linux 命令 文件数量统计
# 查看当前目录下的文件数量(不包含子目录中的文件) ls -l|grep "^-"| wc -l # 查看当前目录下的文件数量(包含子目录中的文件) 注意:R,代表子目录 ls ...
- vi中使用删除键(backspace)只能删除到行首不能跳到上一行怎么处理?
答: 在~/.vimrc中加入以下内容: set backspace=2
- 爬虫中BeautifulSoup4解析器
CSS 选择器:BeautifulSoup4 和 lxml 一样,Beautiful Soup 也是一个HTML/XML的解析器,主要的功能也是如何解析和提取 HTML/XML 数据. lxml 只会 ...
- 【449】backup get weekly tweets
import pandas as pd from datetime import datetime fn = r"D:\OneDrive - UNSW\tweets_flu.csv" ...
- eclipse :代码自动补全不生效解决办法
参考文章:https://blog.csdn.net/qq_35033270/article/details/79285821 请见下图! 恢复缺省值即可!
- java.sql.SQLException: Zero date value prohibited
今天使用mybatis出现了异常 java.sql.SQLException: Zero date value prohibited 查了下原因 mysql文档上写着 Datetimes with a ...
- vscode failed to excute git
将代码提交到github时 提示 “failed to excute git” 解决:配置git git config --global user.email "youremailid@ex ...
- Javaspring+mybit+maven中实现定时任务
背景:在Javaspring中,定时的启动某一个任务时,使用@Scheduled来实现 Javaspring工程创建好之后,直接创建下面的class文件即可.具体的用法可参照 https://www. ...
- nginx做正向代理https遇到SSL_do_handshake()握手失败
SSL_do_handshake() failed (SSL: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number) wh ...
- Appium元素定位难点:混合式的native+webview
现在大部分app都是混合式的native+webview,对应native上的元素通过uiautomatorviewer很容易定位到,webview上的元素就无法识别了. 1.认识识webview & ...