使用Spring Boot+MyBatis框架做查询操作
一.在你建立的工程下创建 Module 选择Spring initializr创建。
二.在Type处选择: Maven Project(项目的构建工具)
三.创建依赖时勾上web,mybatis,mysql(这个看你个人需要吧,可以自主选择)
建立好的项目结构如下:
注意:application.properties和application.yml是同一个东西,均为项目的核心配置文件
内容如下:
#连接数据库
spring.datasource.url=jdbc:mysql://localhost:3306/smbms
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driverClassName=com.mysql.jdbc.Driver
#引入mybatis的配置文件
mybatis:
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.sprboot.pojo
相应的pom.xml文件
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId> <artifactId>springboot</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!--添加web依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--引入spring boot包--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Spring-Mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency> <!-- MySQL --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--使用json对象--> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.49</version> </dependency> <!--使用thymeleaf标签--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
&l b60 t;/project>
相应的接口UserMapper如下:
@Repository
public interface UserMapper {
List<User> getList();
}
service如下:
public interface UserService {
List<User> getList();
}
impl如下:
[blockquote] [p]@Servicepublic class UserServiceImpl implements UserService {[url=mailto:br/>@Resource@Resource@Override@Override
- SpringBoot-Mybatis框架使用与源码解析
- SpringBoot使用Mybatis注解进行一对多和多对多查询
- spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架
- Spring Boot快速入门(五):使用MyBatis(注解形式)进行数据库操作
- 架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(一)
- 使用myeclipse搭建SpringBoot框架,整合thymeleaf模板和mybatis
- SpringBoot中使用MyBatis,使用PageHelper进行分页查询以及碰到的错误
- 在 Spring Boot @Configuration 注解类中使用 Mybatis 查询数据库启动报错
- springboot框架中使用java操作kafka获取数据
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十六)使用JdbcTemplate操作数据库
- springboot+springmvc+mybatis 使用注解对数据库的增、改和查操作
- 架构实战项目心得(七):使用SpringBoot+Dubbo+Mybatisplus+Oracle搭建后台项目框架(二)
- spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架
- SpringBoot之Mybatis操作中使用Redis做缓存
- bootstrap + angularjs + springmvc + mybatis框架之多个输入框(可为空)组合查询
- Java的Hibernate框架数据库操作中锁的使用和查询类型
- 使用 Spring Boot 快速构建 Spring 框架应用
- 使用 Spring Boot 快速构建 Spring 框架应用---学习笔记
- Spring Boot、Mybatis框架整合开发Java RESTful Web Service
- zTree的调用设使用(跨两个系统,两类技术实现的项目案例SpringMVC+Spring+MyBatis和Struts2+Spring+ibatis框架组合)