Mybatis在我的工作中使用
来源:互联网 发布:淘宝千里眼是免费得吗 编辑:程序博客网 时间:2024/03/29 23:17
第一次在工作项目中接触到Mybatis+maven,做一个小记录,让自己以后可以随时回顾,也算是一个方法总结
以管理平台中支付订单的查询为例,首先是页面这样一个表单的提交
<form id="zqOrgPayBillListForm" action="page/zq/order/payBillList.shtml" method="post">
<span style="white-space:pre"></span>其中每个查询条件字段的输入都是一实体的方式 queryParam.mechSeqId:
<span style="white-space:pre"><td class="queryName" nowrap>商户订单号</td><span style="white-space:pre"></span><td class="queryContent"><span style="white-space:pre"></span><input id="mechSeqId" name="queryParam.mechSeqId" value="<s:property value="queryParam.mechSeqId" />" /><span style="white-space:pre"></span></td></span>
<span style="white-space:pre"></span>通过struts.xml中的<pre name="code" class="html"><span style="white-space:pre"></span><!-- 支付订单管理 --><action name="payBillList" method="payBillList" class="zqOrgPayBillAction"><result name="success">/page/zq/order/zqOrgPayBillList.jsp</result></action>的配置来调用 类名为zqOrgPayBillAction的action,当然Action的配置在applicationAction.xml中:
<!--支付转清订单管理 --><bean id="zqOrgPayBillAction" class="com.ylink.ydzf.mp.zq.action.ZqOrgPayBillAction" scope="prototype"><property name="zqMechPayBillAppService" ref="zqMechPayBillAppService" /><property name="zqOrgInfoAppService" ref="zqOrgInfoAppService" /></bean>
其中property为Action中使用到的 Service ,也可以在Action中使用注解的方式注入,这里就不需要配置了。
接下来在看ZqOrgPayBillAction之前先主义一下一个ZqMechPayBillDTO类,与数据库中对应的是ZqMechPayBill类,这里的***DTO表示数据传输使用的类
用 private List<ZqMechPayBillDTO> zqMechPayBillList; //支付订单列表 List<***DTO>来存储查询的订单结果
接下来:
<span style="white-space:pre"></span>adaptQueryParams();//适配查询条件pageData = zqMechPayBillAppService.findPage(pageData, queryParam);<span style="white-space:pre"></span>//查询页面结果zqMechPayBillList = pageData.getRows();<span style="white-space:pre"></span>//结果数据page = new Page(pageData.getPageNumber(), pageData.getPageSize(), pageData.getTotal());// 统计金额totalZqMechPayBill = zqMechPayBillAppService.calPageAmount(queryParam);if (totalZqMechPayBill == null) {totalZqMechPayBill = new ZqMechPayBillDTO();
public PageData<ZqMechPayBillDTO> findPage(PageData<ZqMechPayBillDTO> pageData, ZqMechPayBillDTO queryParam)throws BusiOrderAppCheckedException {try {return zqMechPayBillService.queryPage(pageData, queryParam);} catch (Exception e) {logger.error("", e);throw new BusiOrderAppCheckedException(EErrorCodeMessage.BUSI_SYSTEM_ERROR.getValue(),EErrorCodeMessage.BUSI_SYSTEM_ERROR.getDisplayName());}}
zqMechPayBillAppService又讲参数传值zqMechPayBillService(**APPService为远程调用):
public PageData<ZqMechPayBillDTO> queryPage(PageData<ZqMechPayBillDTO> pageData, ZqMechPayBillDTO queryParam) {List<ZqMechPayBillDTO> items = zqMechPayBillMapper.queryPage(queryParam, pageData.getBeginIndex(), pageData.getEndIndex());long count = zqMechPayBillMapper.queryPageCount(queryParam);pageData.setRows(items);pageData.setTotal(count);return pageData;}在zqMechPayBillService中,参数传进了zqMechPayBillMapper.queryPage中,这里的zqMechPayBillMapper就是对数据库操作的一个接口:
有zqMechPayBillMapper.java(接口)
zqMechPayBillMapper.xml(存放对数据库CURD的sql语句)
在zqMechPayBillMapper.java中有:
List<ZqMechPayBillDTO> queryPage(@Param("queryParam")ZqMechPayBillDTO queryParam, @Param("beginIndex")int beginIndex , @Param("endIndex")int endIndex);即把queryParam 存放进queryParam传入zqMechPayBillMapper.xml,把beginIndex存放进beginIndex,endIndex存放进endIndex传入zqMechPayBillMapper.xml中
在zqMechPayBillMapper.xml中:
有<select id="queryPage" resultMap="EBaseResultMap"> </select>这样包含的语句表示对数据库的操作。
数据取得以后再如前面所说的以zqMechPayBillList传入jsp页面例如:
<span style="white-space:pre"></span><s:if test="zqMechPayBillList != null && zqMechPayBillList.size() > 0"><s:iterator id="bill" value="ZqMechPayBillList" status="st">
<span style="white-space:pre"></span><tr>
<span style="white-space:pre"><td align="center" nowrap><span style="white-space:pre"></span><s:property value="#bill.curryType" /><span style="white-space:pre"></span></td> </span>
<span style="white-space:pre"></span></tr>
<span style="white-space:pre"></span></s:iterator>
<span style="white-space:pre"></span></s:if>
0 0
- Mybatis在我的工作中使用
- 工作中mybatis的使用方式
- 可以在我工作使用的sourceforge优秀项目
- 我的工作在哪里?
- 【MyBatis】在MyBatis中使用in语句
- 在Spring3中使用MyBatis
- 在spring中使用MyBatis
- 在项目中使用mybatis
- 在Eclipse中使用Mybatis
- 在项目中xmlhttp,我的使用
- perl在我工作中的使用
- 【2008年的我】我在中企动力的工作、生活随感~
- 在使用Mybatis框架中遇到的bug
- 在线办公实例:我如何在实际工作中使用超级表格
- 关于log4j在实际工作中使用的一些想法
- 我在深圳的工作历程
- 我的工作应该在第一现场
- 我在华为工作十年的感悟
- 【iOS开发】往Xcode中导入图片注意事项
- 动态分配多维数组
- maven详解
- 用Eclipse生成keystore签名
- list 根据相同字段合并数据
- Mybatis在我的工作中使用
- vc++ 操作COM
- 面试遇到的问题
- 解决AnyConnect在Win8上anyconnect was not able to establish a connection to the specified secure gateway
- 随web容器启动Java类,调用spring容器中的的bean及其方法
- 网桥的个人疑问和解释
- cocos2dx 2.x定时器分析(3)
- 关于Eclipse中导入安卓工程无法生成R.java文件的问题
- 使用struts2标签上传用户头像(二)