Spring Boot Mybatis 配置

 Spring Boot Mybatis 配置

resource/mybatis-config.xml

配置数据库连接方式(jdbc驱动),注册mapper,

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="false"/>
<setting name="localCacheScope" value="STATEMENT"/>
<setting name="useGeneratedKeys" value="true"/>
</settings>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://80.76.180.95" />
<property name="username" value="root" />
<property name="password" value="Password_12#$" />
</dataSource>
</environment>
</environments>


<mappers>
<mapper resource="mapper/TestMapper.xml"/>
<mapper class="com.deep.infra.persistence.sql.mapper.UserMapper"/>
<mapper class="com.deep.infra.persistence.sql.mapper.AgentMapper"/>
<mapper class="com.deep.infra.persistence.sql.mapper.RoleMapper" />


<mapper class="com.deep.infra.persistence.sql.mapper.NoticeMapper"/>
<mapper resource="mapper/BreedingPlanMapper.xml"/>
<mapper resource="mapper/DiagnosisPlanMapper.xml"/>
<mapper resource="mapper/NutritionPlanMapper.xml"/>
<!--<mapper resource="mapper/NoticePlanMapper.xml"/>-->


<mapper resource="mapper/PicMapper.xml"/>
<mapper resource="mapper/MessageMapper.xml"/>
<mapper resource="mapper/GenealogicalFilesMapperxml.xml" />
<mapper resource="mapper/DisinfectFilesMapper.xml" />
<mapper resource="mapper/ImmunePlanMapper.xml"/>
<mapper resource="mapper/RepellentPlanMapper.xml"/>
<mapper resource="mapper/GenealogicalFilesTransMapper.xml"/>
<mapper resource="mapper/DisinfectionArchivesMapper.xml" />
<mapper resource="mapper/OperationFileMapper.xml" />
<mapper resource="mapper/VideoPublish.xml"/>
<mapper resource="mapper/TypeBriefMapper.xml"/>
<mapper resource="mapper/EnvironmentTraceMapper.xml"/>


</mappers>
</configuration>

  
<! DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
< configuration>
< settings>
< setting name= "cacheEnabled" value= "false"/>
< setting name= "localCacheScope" value= "STATEMENT"/>
< setting name= "useGeneratedKeys" value= "true"/>
</ settings>
< environments default= "development">
< environment id= "development">
< transactionManager type= "JDBC"/>
< dataSource type= "POOLED">
< property name= "driver" value= "com.mysql.jdbc.Driver" />
< property name= "url" value= "jdbc:mysql://80.76.180.95" />
< property name= "username" value= "root" />
< property name= "password" value= "Password_12#$" />
</ dataSource>
</ environment>
</ environments>


< mappers>
< mapper resource= "mapper/TestMapper.xml"/>
< mapper class= "com.deep.infra.persistence.sql.mapper.UserMapper"/>
< mapper class= "com.deep.infra.persistence.sql.mapper.AgentMapper"/>
< mapper class= "com.deep.infra.persistence.sql.mapper.RoleMapper" />


< mapper class= "com.deep.infra.persistence.sql.mapper.NoticeMapper"/>
< mapper resource= "mapper/BreedingPlanMapper.xml"/>
< mapper resource= "mapper/DiagnosisPlanMapper.xml"/>
< mapper resource= "mapper/NutritionPlanMapper.xml"/>
<!--<mapper resource="mapper/NoticePlanMapper.xml"/>-->


< mapper resource= "mapper/PicMapper.xml"/>
< mapper resource= "mapper/MessageMapper.xml"/>
< mapper resource= "mapper/GenealogicalFilesMapperxml.xml" />
< mapper resource= "mapper/DisinfectFilesMapper.xml" />
< mapper resource= "mapper/ImmunePlanMapper.xml"/>
< mapper resource= "mapper/RepellentPlanMapper.xml"/>
< mapper resource= "mapper/GenealogicalFilesTransMapper.xml"/>
< mapper resource= "mapper/DisinfectionArchivesMapper.xml" />
< mapper resource= "mapper/OperationFileMapper.xml" />
< mapper resource= "mapper/VideoPublish.xml"/>
< mapper resource= "mapper/TypeBriefMapper.xml"/>
< mapper resource= "mapper/EnvironmentTraceMapper.xml"/>


</ mappers>
</ configuration>

src/infra.persistence.sql/mapper/TestMapper.java
实现对数据库操作的CRUD 接口

  


src/domain/service/TestService.java

实例化CRUD接口
package com.deep.domain.service;
import com.deep.domain.model.TestModel;
import com.deep.infra.persistence.sql.mapper.TestMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
 * Created by zhongrui on 2018/2/1.
 */
@Service
public class TestService {
  @Resource
  private TestMapper testMapper;

  public TestModel getTestModel(String index) {
    TestModel model = this.testMapper.getTestModelById(index);
    return model;
  }

}


src/domain/model/TestModel.java

用于接收前端信息后对数据库进行操作

package com.deep.domain.model;
public class TestModel {
  private int id;
  private String message;

  public int getId() {
    return id;
  }
  public void setId(int id) {
    this.id = id;
  }
  public String getMessage() {
    return message;
  }
  public void setMessage(String message) {
    this.message = message;
  }

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot Mybatis Flex是一个用于在Spring Boot项目中集成Mybatis Flex的工具。根据提供的引用内容,可以看出Mybatis Flex提供了不同的依赖项,以适应不同的场景。 如果只使用了Mybatis,而没有使用Spring,可以使用以下依赖项: ```xml <dependency> <groupId>com.mybatis-flex</groupId> <artifactId>mybatis-flex-core</artifactId> <version>1.2.0</version> </dependency> ``` \[1\] 如果使用了Spring,可以使用以下依赖项: ```xml <dependency> <groupId>com.mybatis-flex</groupId> <artifactId>mybatis-flex-spring</artifactId> <version>1.2.0</version> </dependency> ``` \[2\] 如果使用了Spring Boot,可以使用以下依赖项: ```xml <dependency> <groupId>com.mybatis-flex</groupId> <artifactId>mybatis-flex-spring-boot-starter</artifactId> <version>1.2.0</version> </dependency> ``` \[3\] 此外,根据提供的代码片段,可以看出创建了一个名为`tb_account`的数据库表,并定义了一个名为`Account`的实体类和Mapper接口。`Account`类中包含了`id`、`userName`、`age`和`birthday`等属性。 综上所述,Spring Boot Mybatis Flex是一个用于在Spring Boot项目中集成Mybatis Flex的工具,可以根据不同的场景选择相应的依赖项,并通过实体类和Mapper来操作数据库。 #### 引用[.reference_title] - *1* *2* *3* [Mybatis-Flex快速入门教程](https://blog.csdn.net/qq_19309473/article/details/130417630)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值