当前位置: 首页 > news >正文

网站建设課程有哪些推广平台和渠道

网站建设課程,有哪些推广平台和渠道,.net开发网站怎么样,有什么那个网站大家好#xff0c;我是王有志。 今天给大家带来的是一道来自京东的 MyBatis 面试题#xff1a;MyBatis 中有几种加载映射器#xff08;Mapper.xml#xff09;的方式#xff1f; 常见加载 MyBatis 映射器的方式有 5 种#xff0c;可以根据不同的使用方式来进行具体区分我是王有志。 今天给大家带来的是一道来自京东的 MyBatis 面试题MyBatis 中有几种加载映射器Mapper.xml的方式 常见加载 MyBatis 映射器的方式有 5 种可以根据不同的使用方式来进行具体区分 MyBatis 原生应用即不与 Spring 或 Spring Boot 集成可以通过配置文件和 Java 编码的方式加载映射器MyBatis 与 Spring 集成可以通过加载 Spring Bean 的方式完成 MyBatis 映射器的加载MyBatis 与 Spring Boot 集成可以通过MapperScan或Mapper注解完成 MyBatis 映射器的加载。 下面我们来具体看下每种方式是如何加载 MyBatis 映射器的。 原生 MyBatis 应用 原生 MyBatis 应用中即不与 Spring 或 Spring Boot 集成的 MyBatis 应用可以通过两种方式加载映射器Mapper.xml 通过 myabtis-config.xml 加载映射器通过 Java 编码的方式加载映射器。 通过 mybatis-config.xml 加载映射器 与 MyBatis入门中实现的简单例子一样只需要在 mybatis-config.xml 中配置映射器即可 ?xml version1.0 encodingUTF-8 ? !DOCTYPE configuration PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-config.dtdconfiguration!-- 省略环境配置 --mappersmapper resourcemapper/UserMapper.xml/mapper resourcemapper/CompanyMapper.xml//mappers /configuration通过 Java 编码的方式加载映射器 MyBatis入门中的附录中同样有相关的例子 DataSource dataSource new PooledDataSource(com.mysql.cj.jdbc.Driver, jdbc:mysql://localhost:3306/mybatis, root, 123456); TransactionFactory transactionFactory new JdbcTransactionFactory();Environment environment new Environment(development, transactionFactory, dataSource); Configuration configuration new Configuration(environment);// 加载映射器 configuration.addMapper(UserMapper.class);如果希望加载某个包下的全部 Mapper.xml可以使用Configuration#addMappers进行加载 configuration.addMappers(com.wyz.mapper);MyBatis 与 Spring 集成 MyBatis 与 Spring 集成后可以通过加载 Bean 的方式加载 MyBatis 的映射器Mapper.xml我们还是按照 MyBatis入门中的步骤先完成 Java 对象 UserDOJava 接口 UserMapper 的创建接着是编写 MyBatis 的映射器 UserMapper.xml最后我们还需要引入相关依赖 dependencies!-- 省略 MySQLjunit等依赖 --dependencygroupIdorg.mybatis/groupIdartifactIdmybatis-spring/artifactIdversion3.0.3/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-core/artifactIdversion6.1.4/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion6.1.4/version/dependency /dependencies接下来我们通过注入 Spring Bean 的方式来加载 Mapper.xml这里我们创建 spring-beans.xml 配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdbean iddataSource classorg.springframework.jdbc.datasource.DriverManagerDataSourceproperty namedriverClassName valuecom.mysql.cj.jdbc.Driver/property nameurl valuejdbc:mysql://localhost:3306/mybatis/property nameusername valueroot/property namepassword value123456//beanbean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBeanproperty namedataSource refdataSource/property namemapperLocations valuemapper/UserMapper.xml//bean!-- 通过 Spring Bean 的方式加载 MyBatis 映射器--bean iduserMapper classorg.mybatis.spring.mapper.MapperFactoryBeanproperty namemapperInterface valuecom.wyz.mapper.UserMapper/property namesqlSessionFactory refsqlSessionFactory//bean /beans最后我们来测试 package com.wyz.mapper;import com.wyz.entity.UserDO; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.List;Slf4j public class UserMapperTest {Testpublic void test(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring-beans.xml);UserMapper userMapper applicationContext.getBean(userMapper, UserMapper.class);ListUserDO users userMapper.selectAll();for(UserDO user : users) {System.out.println(user.toString());}} }MyBatis 与 Spring Boot 集成 MyBatis 与 Spring Boot 集成后可以通过注解的方式或配置文件的方式加载 MyBatis 的映射器Mapper.xml使用起来非常的方便。首先我们还是做好前期的准备创建 Java 对象 UserDOJava 接口 UserMapperMyBatis 的映射器文件 UserMapper.xml接着我们来写 Spring Boot 的配置文件主要完成数据库相关的配置 spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/mybatisusername: rootpassword: 123456通过 MapperScan 注解加载映射器 我们需要在 Spring Boot 应用的启动类上使用MapperScan注解并扫描 Mapper 文件所在的包来加载 MyBatis 的映射器 package com.wyz;import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication MapperScan(com.wyz.mapper) public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);} }最后我们来进行测试 package com.wyz.mapper;import com.wyz.entity.UserDO; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import java.util.List;SpringBootTest public class UserMapperTest {Autowiredprivate UserMapper userMapper;Testpublic void test() {ListUserDO users userMapper.selectAll();for(UserDO user : users) {System.out.println(user.toString());}} }通过 Mapper 注解加载映射器 除了使用MapperScan注解加载某些包下的映射器外还可以为每个映射器接口添加Mapper接口来加载映射器我们把 Spring Boot 启动类上的MapperScan注解删除为 UserMapper 接口添加Mapper注解 package com.wyz.mapper;import com.wyz.entity.UserDO;import java.util.List;public interface UserMapper {ListUserDO selectAll(); }好了今天的内容就到这里了如果本文对你有帮助的话希望多多点赞支持如果文章中出现任何错误还请批评指正。最后欢迎大家关注分享硬核 Java 技术的金融摸鱼侠王有志我们下次再见
http://www.w-s-a.com/news/476333/

相关文章:

  • 自适应网站好处wordpress ftp验证
  • 网站建设的时间免费ppt模板的网站
  • 建个人网站一般多少钱ppt下载网站哪个好
  • 网站建设比赛网站建设合同标的怎么写
  • 中国做的儿童编程网站网站建设模板网站
  • 电脑做系统网站微信开店
  • site之后网站在首页说明说明网络舆情分析师怎么考
  • 本溪网站建设兼职wordpress lapa
  • 官网网站设计费用vue大型网站怎么做路由
  • 青海省安建设管理部门网站厦门网站快照优化公司
  • 张家港建网站公司网站开发 认证
  • 网站建设方式优化兰州医院网站制作
  • 怎么创造网站wordpress伪静态规则怎么写
  • 自己怎么做一元购物网站信誉好的合肥网站推广
  • 做网站的骗术有什么好的网站设计思想的博客
  • 网站建设工作 方案企查查企业信息查询在线
  • 上海外贸建站商城定制软件安卓
  • 成都网站建设_创新互联wordpress 相邻文章
  • 电子商务网站制作步骤免费建网站知乎
  • 龙岩有什么招聘本地网站团购网站 方案
  • 服务器运行一段时间网站打不开注册公司名字核名查询系统
  • 企业网站改版的意义响应式网站建设新闻
  • 大连金州新区规划建设局网站金坛市建设局网站
  • 有哪些做排球比赛视频网站wordpress 教师工作坊
  • 深圳好点的网站建设公司互联网企业信息服务平台
  • 下载空间大的网站建设哈尔滨网站制作软件
  • 南城网站仿做无锡网站制作哪家价格便宜
  • c做的网站营销策划课程
  • 免费网站404免费进入重庆的公需科目在哪个网站做
  • 网站空间租用费用网站建设公司怎么宣传