mapper

SpringBoot整合MyBatis

独自空忆成欢 提交于 2019-12-03 20:53:08
1.在原有的依赖中,添加MyBatis的依赖 <!--SpringBoot整合MyBatis--><dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version></dependency> 2.配置相关数据源信息(application.yml)。 #DataBase Configurationspring: datasource: driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/springbootdemo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT username: root password: 123#SpringDataJPA Configuration jpa: database: mysql show-sql: true generate-ddl: true 3.创建实体类,对应数据库表中的字段,并添加getter、setter和toString方法 4

xxxMapper.xml文件的头部配置

只愿长相守 提交于 2019-12-03 20:41:21
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.offcn.Mapper.MUserMapper"> <select id="getUserList" resultType="com.offcn.POJO.MUser">    select * from user  </select></mapper> 来源: https://www.cnblogs.com/cjh-code/p/11800937.html

Mybatis中使用association及collection进行一对多双向关联示例

心不动则不痛 提交于 2019-12-03 16:58:18
XML版本: 实体类: package com.sunwii.mybatis.bean; import java.util.ArrayList; import java.util.List; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; @Data @ToString @NoArgsConstructor public class Dept { private Integer id; private String name; private List<Employee> employees = new ArrayList<Employee>(); public Dept(Integer id) { this.id = id; } public String toLazyString() { return "Dept:{id: "+this.id+" ; name: "+this.name+"}"; } } package com.sunwii.mybatis.bean; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class Employee {

SpringBoot整合mybatis及注意事项

青春壹個敷衍的年華 提交于 2019-12-03 15:30:34
SpringBoot整合mybatis及注意事项 主要步骤 添加依赖 mybatis 在配置文件中配置数据源信息 编写pojo mapper接口 mapeer映射文件 手动配置mybatis的包扫描 ​     在主启动类添加@MapperScan 1:导入依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> 2:配置数据源信息 在application.yml中进行配置 #DB Configation spring: datasource: driverClassName: com.mysql.jdbc.Driver    //注意如果出现了无法连接数据库问题,在tx后面添加 ?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT url: jdbc:mysql://127.0.0.1:3306/tx username: root password: 813100 jpa: database: MySQL show-sql: true

springboot整合mybatis错误 Invalid bound statement (not found): com.yuan.mapper.UserMapper.getUserList

这一生的挚爱 提交于 2019-12-03 15:30:07
出现的原因是 src文件下的mapper有mapper接口和映射文件,而target下的mapper文件却没有映射文件 ===========================解决方案================================== 1.把映射文件 放到resources 目录下 结构目录一模一样 2.在pom.xml中导入以下代码 <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> <filtering>false</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId>

springboot整合mybatis

偶尔善良 提交于 2019-12-03 15:29:18
添加mybatis依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> 配置文件中配置数据源信息 spring: datasource: driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/springboot username: root password: root jpa: database: MySQL show-sql: true generate-ddl: true View Code 编写pojo mapper接口 以及mapper映射文件 pojo public class MUser implements Serializable { private int id; private String username; private String password; private String name; View Code mapper接口 public interface UserMapper { List<MUser>

SpringBoot整合mybatis及注意事项

隐身守侯 提交于 2019-12-03 15:16:39
SpringBoot整合mybatis及注意事项 主要步骤 添加依赖 mybatis 在配置文件中配置数据源信息 编写pojo mapper接口 mapeer映射文件 手动配置mybatis的包扫描 ​     在主启动类添加@MapperScan 1:导入依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> 2:配置数据源信息 在application.yml中进行配置 #DB Configation spring: datasource: driverClassName: com.mysql.jdbc.Driver    //注意如果出现了无法连接数据库问题,在tx后面添加 ?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT url: jdbc:mysql://127.0.0.1:3306/tx username: root password: 813100 jpa: database: MySQL show-sql: true

SpringBoot整合MyBatis

妖精的绣舞 提交于 2019-12-03 15:12:14
步骤: 1.添加mybatis依赖 <!--mybatis--> < dependency > < groupId > org.mybatis.spring.boot </ groupId > < artifactId > mybatis-spring-boot-starter </ artifactId > < version > 1.1.1 </ version > </ dependency > 2.在配置文件中配置数据源信息 application.properties文件 spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://127.0.0.1:3306/访问的数据库名称spring.datasource.username=数据库的用户名spring.datasource.password=数据库的密码 3.编写pojo (toString,getter,setter,全参无参构造) mapper接口 mapeer映射文件 控制层: @Controller @RequestMapping( "/user") public class UserController { @Autowired private UserMapper

SpringBoot整合Mybatis

浪子不回头ぞ 提交于 2019-12-03 15:06:44
1、 依赖在上一篇随笔中已经导入,这里不再展示 2、 数据源信息也 上一篇随笔中 已经配置过 3、 编写 pojo 对象 MUser 1 package com.offcn.pojo; 2 3 import lombok.AllArgsConstructor; 4 import lombok.Data; 5 import lombok.NoArgsConstructor; 6 7 import javax.persistence.*; 8 9 @Entity 10 @Data 11 @NoArgsConstructor 12 @AllArgsConstructor 13 @Table(name = "user") 14 public class MUser { 15 16 @Id 17 @GeneratedValue(strategy = GenerationType.IDENTITY) 18 private Integer uid; 19 private String uname; 20 private String pwd; 21 private String gender; 22 private String phone; 23 } 4 、 MUserMapper 接口 1 package com.offcn.mapper; 2 3 import com.offcn.pojo

第七天.spring boot 整合mybatis

独自空忆成欢 提交于 2019-12-03 15:05:36
1.整合思路:   1.1 添加依赖 mybatis   1.2 在配置文件中配置数据源信息   1.3 编写pojo mapper接口 mapeer映射文件    1.4 手动配置mybatis的包扫描, 在主启动类添加@MapperScan 1.5 启动springboot服务器 2.开始工程部署:   2.1:添加依赖 mybatis      <!--整合springboot与mybatis的整合--> <dependencies> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> </dependencies> <!--将mapper下的mapper接口与mapper映射文件放在一个mapper包下所需要的依赖--> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes>