一、聚合函数查询
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(); } }
二、模糊查询的几种写法
1.
STUDENTNAME like '%${studentName}%'
2.
STUDENTNAME like '%'||#{studentName}||'%'