Spring Boot整合mybatis

引入依赖

		  <dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter<artifactId>
			<version>1.3.0</version>
		</dependency>
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<scope>runtime</scope>
	</dependency>
	<dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>druid</artifactId>
		<version>1.0.29</version>
	</dependency>

在application.properties配置文件中引入数据源:

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

spring.http.multipart.maxFileSize=1000Mb
spring.http.multipart.maxRequestSize=1000Mb
***spring.datasource.url=jdbc:mysql://127.0.0.1:3306/publicPlatform?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.jdbc.Driver***
spring.jpa.properties.hibernate.hbm2ddl.auto=update
mybatis.mapper-locations=classpath:com/qianying/publicPlatform/mybatis/mapper/*.xml
mybatis.type-aliases-package=com.qianying.publicPlatform.mybatis.pojo
server.port=8888

通过逆向工程产生实体类,mapper 和mapper.xml(这里不需要再里面写sql语句)

再mapper中写CRUD的方法(这里只写一个示例)

 @Delete("delete from re_keyword where KeywordId = #{KeywordId}")
    int delete(int id);

创建service

在这里插入图片描述

写一个controller

在这里插入图片描述

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页