springmvc-mybatis 之mapper代理开发

SSM框架实战:基于Spring+SpringMVC+MyBatis的增删改查项目练习 SSM(Spring + SpringMVC + MyBatis)是当前Java企业级开发中广泛应用的轻量级框架组合,三者各司其职、协同工作,构建出结构清晰、易于维护的Web应用系统。Spring作为核心容器,通过控制反转(IoC)和依赖注入(DI)实现组件间的松耦合管理,并以面向切面编程(AOP)支持横切关注点的模块化处理;SpringMVC基于MVC设计模式,依托统一调度请求,结合注解驱动开发极大提升了表现层的灵活性与可读性;MyBatis。 阅读详情

1.mapper代理与原始dao开发的区别

1.1抽出许多公共的模块,如获得session,关闭资源
1.2不用实现dao接口
1.3易于维护 ,修改不用重新编译java文件

2.开发规范

2.1mapper.xml文件中的命名空间必须与包名相同

<!-- 开发规范:  1.命名空间必须与包名一样  -->
<mapper namespace="com.ssm.mapping.UserMapperDAO">

2.2接口类与mapper.xml在同一个包下

2.3接口中的方法必须与mapper.xml中的id一一对应
2.4接口中的方法参数与mapper.xml中的parameterType指定类型对应
2.5接口中的方法必须与mapper.xml中的resultType一致

<!-- #{}表示一个占位符 根据id查询用户-->
    <select id="findUserById" parameterType="int" resultType="com.ssm.model.User">
        SELECT * FROM USER WHERE id=#{value}
    </select>

    <select id="findUserByName" parameterType="java.lang.String" resultType="com.ssm.model.User">
        SELECT * FROM USER WHERE USERNAME LIKE '%${value}%'
    </select>

public interface UserMapperDAO {

    public User findUserById(int id);
    public List<User> findUserByName(String username);
    public void insertUser(User user);
    public void deleteUser(int id);
    public void updateUser(User user);
}

3.在spring配置文件中配置mepper代理bean

    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 基于原始的dao开发 需要dao实现类 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:sqlmapconfig.xml"></property>
    </bean>


    <!-- 基于mapper代理的dao 开发不需要dao实现类  -->
    <bean id="mapperFacetoryBean" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <!-- 构造方法需要两个参数sqlsessionfactory 与  mapperInterface -->
        <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
        <property name="mapperInterface" value="com.ssm.mapping.UserMapperDAO"></property>
    </bean>

4.在需要的地方注入

    //接口对象,自动注入
    @Autowired
    private UserMapperDAO mapperFacetoryBean;

以上,

SpringMVC + Mybatis整合Mapper方式 NULL 博文链接:https://panyongzheng.iteye.com/blog/2103441 立即下载

相关推荐

STM32CubeMX+FreeRTOS+CAN总线+传感器实战:多任务系统与通信融合开发详解

本文详细介绍了基于STM32CubeMX和FreeRTOS的CAN总线与光电传感器融合开发实战。通过多任务系统设计,实现传感器数据采集与CAN通信的协同工作,提供完整的配置例程和调试技巧,适用于工业控制与机器人感知等应用场景。

n2o3p4的博客 735

SpringMVC之MapperScannerConfigurer详解

Spring注入映射器在SpringMVC中,你可以不必为每一个DAO都去写相应的实现,而交给SpringMVC替你创建。为了代替手工使用 SqlSessionDaoSupport 或 SqlSessionTemplate 编写数据访问对象 (DAO)的代码,MyBatis-Spring 提供了一个动态代理的实现:MapperFactoryBean。这个类 可以让你直接注入数据映射器接口到你的 se

wtopps的专栏 2万+

别再只用CANape测数据了!手把手教你用ASAP2 Studio编辑A2L文件(附MAP文件更新避坑指南)

本文深入探讨ASAP2 Studio在ECU开发中的高阶应用,特别是如何利用其编辑A2L文件并同步更新MAP文件,提升测量标定效率。文章详细解析了ASAP2 Studio的双向同步能力、MAP文件更新全流程及变量管理技巧,帮助工程师避免常见错误,优化工作流程。

weixin_26833939的博客 508

SpringMVC开发流程

1、创建controller.AttributeTemplateController类,在类上添加@RestController注解、@RequestMapping("/attribute-template")注解在类中自动装配对应的Service接口类型的对象,在类中声明成立请求的方法,方法上需要添加@PostMapping("add-new")注解,在方法体中调用Server实现功能,并且在调用时使用try....catch捕获并处理异常。2、完成后,重启项目,通过API文档测试访。

2301_78106512的博客 219

Windows 11安装realtek audio control

Windows 11安装realtek audio control,解决无法链接RPC问题

m0_46144825的博客 8万+

告别付费!手把手教你用DataV.GeoAtlas获取全国街道级GeoJSON数据(附完整避坑指南)

本文详细介绍了如何免费使用阿里云DataV.GeoAtlas工具获取全国街道级GeoJSON数据。通过可视化选取、格式转换、数据校验等步骤,提供了一套完整的避坑指南和工作流,帮助前端和可视化开发者高效解决高精度地图数据获取难题,节省成本并提升开发效率。

weixin_29085865的博客 905

【SpringMVC+mybatis】6.mybatis mapper代理方法

1.思路(mapper代理开发规范) (1)编写mapper.xml映射文件 (2)mapper接口需要遵循一些开发规范,mybatis可以自动生产mapper接口实现类代理对象。 2.开发规范: (1)在mapper.xml中namespace等于mapper接口地址 (2)mapper.java接口中的方法名和mapper.xml中statement的id一致 (3)mapper.

返璞归真 628

DDR内存Prefetch机制详解:从DDR1到DDR4的技术演进与性能提升

本文深入解析DDR内存Prefetch机制从DDR1到DDR4的技术演进与性能提升。通过分析Prefetch技术的实现原理与Burst传输的协同机制,揭示DDR1的2n Prefetch、DDR2的4n Prefetch、DDR3的8n Prefetch以及DDR4的Bank Group架构创新如何显著提升内存带宽与系统性能。

weixin_30369041的博客 540

【Spring+SpringMVC+MyBatis深入学习及搭建】02.MyBatis原始Dao开发和mapper代理开发

转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6869133.html  前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(一)——MyBatis的基础知识。MybatisFirst中存在大量重复的代码。这次简化下代码: 使用MyBatis开发Dao,通常有两种方法,即原始Dao开发方法和Mapper接口开发方法。 1.Sql

剑翊乾坤 304

ESP32-CAM图传小车:端边协同的嵌入式视觉系统设计

在物联网边缘智能场景中,嵌入式视觉系统需平衡实时性、算力与成本。其核心在于理解图像采集、硬件编码、低延迟传输与分层计算的基本原理——OV2640等CMOS传感器配合JPEG硬件编码可显著降低主控负载;TCP流式协议比HTTP/RTSP更适配资源受限MCU;而‘计算卸载’架构将OpenCV等重负载移至Android端,使ESP32专注实时控制与传输,既发挥FreeRTOS任务调度优势,又规避了PSRAM带宽与内存瓶颈。该模式广泛适用于教育机器人、智能巡检及DIY视觉终端等场景,本文以WiFi图传坦克小车为载体

weixin_42524864的博客 375

AI Agent技能评测框架SkillsBench:从黑盒评估到白盒技能拆解

在人工智能领域,模型评估是衡量技术进展的核心环节。传统评测基准如GLUE、MMLU主要关注模型的通用认知能力,但实际工程应用中,AI Agent需要的是在复杂场景中协调多种能力的“职业技能”。SkillsBench创新性地将Agent能力进行原子化拆解,定义了理解规划、工具调用、推理决策、交互安全等技能维度,并通过领域专家构建的评测集确保生态效度。这一框架为Agent开发提供了精准的“度量衡”,使性能优化从经验驱动转向数据驱动,同时为不同模型和框架提供了公平比较的基础,推动了AI Agent生态从“野蛮生长

weixin_30530339的博客 389

Spring+SpringMVC+MyBatis入门(二)——MyBatis原始Dao开发和mapper代理开发

MybatisFirst中存在大量重复的代码。这次简化下代码: 使用MyBatis开发Dao,通常有两种方法,即原始Dao开发方法和Mapper接口开发方法。 1.SqlSession使用范围 1.1 SqlsessionFactoryBuilder 通过SqlSessionFact...

chenjue0956的博客 190

倍福--实现TCP/IP的配置

控制器为CX5120,需要和上位机做通信,选择TCP/IP的通讯方式,本文介绍TCP/IP通信的操作步骤。 目 录 软硬件版本 3 1.1. 倍福Beckhoff 3 1.1.1. 控制器硬件 3 1.1.2. 控制软件 3 1.2. 串口调试助手 3 1.2.1. TCP调试通信助手 3 授权文件 3 2.1 Lib文件 3 2.2. CAB文件 4 PLC程序编写 4 3.1. 引入TCP/IP库文件 4 3.2. Client端程序 5 3.2.1. 建立相关变量 5 3.3.2. 编写连接功能块

weixin_41883890的博客 5730

Spring+SpringMVC+MyBatis深入学习及搭建(二)——MyBatis原始Dao开发和mapper代理开发

转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6869133.html 前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(一)——MyBatis的基础知识。MybatisFirst中存在大量重复的代码。这次简化下代码: 使用MyBatis开发Dao,通常有两种方法,即原始Dao开发方法和Mapper接口开发方法。 1.Sql...

weixin_34290000的博客 148

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Spring+SpringMVC+MyBatis深入学习及搭建(二)——MyBatis原始Dao开发和mapper代理开发(转发同上)...

前面有写到Spring+SpringMVC+MyBatis深入学习及搭建(一)——MyBatis的基础知识。MybatisFirst中存在大量重复的代码。这次简化下代码: 原地址:http://www.cnblogs.com/shanheyongmu/p/7121016.html 使用MyBatis开发Dao,通常有两种方法,即原始Dao开发方法和Mapper接口开发方法。 1.SqlS...

qq_34670974的博客 109

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

JavaEE_Mybatis_SpringMVC_整合开发_lesson2_Mapper代理开发方式

百度云:Myeclipse2014项目(包括数据库表和数据) http://pan.baidu.com/s/1i4ij4Kt 上接lessson1,SSM框架整合, 原始Dao开发 本例展示如何使用Mapper代理的开发方式,开发SSM(Spring Springmvc Mybaits) 主要内容包括 1.SqlMapConfig.xml (Mybatis配置

迎难而上 1270

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

JavaEE_Mybatis_SpringMVC_Mybatis_lesson3_ Mapper代理的开发方式

主要内容 1.  SqlMapConfig.xml 文件(全局的配置文件),  2.  UserMapper.xml(接口DAO所对应的sql),     3.  UserMapper.java(接口DAO),   4.  User.java(JavaBean),  5.  JUnit 对DAO的测试 1. 全局的SqlMapConfig.xml 配置文件 ,该文件目的

迎难而上 782

SpringMVC详解

持久层:负责将数据保存到数据库的那一层代码框架:半成品软件,是一套可重用的软件基础代码模型,在框架的基础上构建软件、编写更加高效。

fanTuanye的博客 2946

MyBatis+Spring MVC开发指南(一)

前言 MyBatis+Spring MVC这套组合,在实际互联网项目中非常流行,博主工作中也涉及过,打算由浅入深、系统的写出来!这个系列将会涵盖MyBatis开发详解、Spring MVC开发详解,以及2者的结合使用,并会分析它们的原理!(可以参考博主的另一篇文章了解Spring MVC原理:《写出我的第一个框架:迷你版Spring MVC》)   没有MyBatis之前 在早期,我们都...

勇往直前的专栏 384

Spring+SpringMVC+Mybatis入门

一、Spring 1、Spring环境搭建 调整项目环境 修改JDK版本 修改单元测试版本 删除build标签中pluginManagement标签 添加Spring框架的依赖坐标 添加Spring配置文件 2、SpringIOC的Bean对象实例化模拟 1)定义Bean属性对象 package cn.ken.virtual_ioc; /** * myBean对象 * 用来接收配置文件中bean标签的id和class属性值 */ public class MyBean { priva

qq_25046827的博客 1510

【mybatis】学习笔记4 Spring+ mybatis 整合

附上学习视频黑马程序员https://www.iqiyi.com/v_19rrad4y88.html#curid=623832100_d64bcfbae20d0fef8e67a50d3e1293b1 applicationContext.xml 配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xs...

aoduanrou3097的博客 106
上一篇: linux之hbase安装
下一篇: mybatis之typealiases定义
cst_code
博客等级 码龄10年 4粉丝 59原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值