码迷,mamicode.com
首页 > 数据库 > 详细

MyBatis+Oracle

时间:2020-01-11 21:56:59      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:apache   auto   version   ring   oct   count   doctype   XML   mapper   

一、聚合函数查询

1.配置实体类

package com.demo;

public class demo {
  //接收集合函数
  private String count;
  private String sum;

}

2.配置MyBatis映射

.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"      
	"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">

<mapper namespace="com.demo.demoDao">
	
	<resultMap id="demo" type="com.demo.demo">
		<result column="count" property="count"/>
		<result column="sum" property="sum"/>
	</resultMap>

	<select id="getSum" resultMap="demo">
		SELECT
		    count(*) as count,
		    sum(*) as sum
		FROM
			table_name
	</select>
</mapper>

.java

package com.demo;

public interface demoDao{

    public demo getSum(demo demo);

}

  

3.业务层

package com.demo;

@Service
public class demoService{

	@Autowired
	private demoDao demoDao;
        
        public void getSum(Demo demo){
        Demo result = demoDao.getsum(demo);
        String sum = result.getsum;
        String count = result.getCount();
      }


}    

  

MyBatis+Oracle

标签:apache   auto   version   ring   oct   count   doctype   XML   mapper   

原文地址:https://www.cnblogs.com/zhang20190701/p/12181101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!