add: 新增mapper的demo
This commit is contained in:
@@ -147,6 +147,7 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa
|
|||||||
//4、叫空载具
|
//4、叫空载具
|
||||||
TaskFactory taskFactory = new TaskFactory();
|
TaskFactory taskFactory = new TaskFactory();
|
||||||
AbstractTask task = taskFactory.getTask("HNMLTask");
|
AbstractTask task = taskFactory.getTask("HNMLTask");
|
||||||
|
//
|
||||||
task.apply(param);
|
task.apply(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.nl.wms.sch.task_manage.task.tasks;/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Description:
|
||||||
|
* @Date: 2023/5/19
|
||||||
|
*/public class HNQKTask {
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.nl.wms.sch.task_manage.task.tasks.mapper;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Description: mapper接口
|
||||||
|
* @Date: 2023/5/23
|
||||||
|
*/
|
||||||
|
public interface TestMapper extends BaseMapper<JSONObject> {
|
||||||
|
|
||||||
|
List<HashMap<String, Object>> getAll();
|
||||||
|
|
||||||
|
JSONObject getAll2();
|
||||||
|
|
||||||
|
List<JSONObject> getAll3();
|
||||||
|
|
||||||
|
JSONArray getAll4();
|
||||||
|
|
||||||
|
JSONArray getAll5();
|
||||||
|
|
||||||
|
HashMap<String, Object> getAll6();
|
||||||
|
|
||||||
|
JSONObject getAll7();
|
||||||
|
|
||||||
|
JSONArray getAll8();
|
||||||
|
|
||||||
|
JSONArray getAll9();
|
||||||
|
|
||||||
|
JSONObject getAll10(HashMap map);
|
||||||
|
|
||||||
|
JSONArray getAll11(JSONObject map);
|
||||||
|
|
||||||
|
JSONArray getAll12(List<String> list);
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="org.nl.wms.sch.task_manage.task.tasks.mapper.TestMapper">
|
||||||
|
<resultMap id="selectPoint" type="java.util.HashMap">
|
||||||
|
<result property="point_code" column="point_code"/>
|
||||||
|
<result property="point_name" column="point_name"/>
|
||||||
|
<result property="region" column="region_name"/>
|
||||||
|
</resultMap>
|
||||||
|
<resultMap id="selectPoint2" type="com.alibaba.fastjson.JSONObject">
|
||||||
|
<result property="point_code" column="point_code"/>
|
||||||
|
<result property="point_name" column="point_name"/>
|
||||||
|
<result property="region" column="region_name"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="getAll" resultMap="selectPoint">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
</select>
|
||||||
|
<select id="getAll2" resultMap="selectPoint2">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
WHERE point_code = 'HNJ01'
|
||||||
|
</select>
|
||||||
|
<select id="getAll3" resultMap="selectPoint2">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
</select>
|
||||||
|
<select id="getAll4" resultMap="selectPoint2">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
</select>
|
||||||
|
<select id="getAll5" resultMap="selectPoint">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
</select>
|
||||||
|
<select id="getAll6" resultType="java.util.HashMap">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
WHERE point_code = 'HNJ01'
|
||||||
|
</select>
|
||||||
|
<select id="getAll7" resultType="com.alibaba.fastjson.JSONObject">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
WHERE point_code = 'HNJ01'
|
||||||
|
</select>
|
||||||
|
<select id="getAll8" resultType="com.alibaba.fastjson.JSONObject">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
</select>
|
||||||
|
<select id="getAll9" resultType="java.util.HashMap">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
</select>
|
||||||
|
<select id="getAll10" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.util.HashMap">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
WHERE 1 = 1
|
||||||
|
<if test="pointCode != '' and pointCode != null">
|
||||||
|
AND point_code = #{pointCode}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
<!-- 查询所有数据 -->
|
||||||
|
<select id="getAll11" resultType="com.alibaba.fastjson.JSONObject" parameterType="com.alibaba.fastjson.JSONObject">
|
||||||
|
<!-- 查询所有数据 -->
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
<where>
|
||||||
|
<if test="pointCode != '' and pointCode != null">
|
||||||
|
AND point_code = #{pointCode} -- 条件过滤
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
<select id="getAll12" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.util.List">
|
||||||
|
SELECT point_code, point_name, region_name
|
||||||
|
FROM sch_base_point
|
||||||
|
<where>
|
||||||
|
point_code IN
|
||||||
|
<foreach collection="list" item="code" separator="," open="(" close=")">
|
||||||
|
#{code}
|
||||||
|
</foreach>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
package org.nl.task;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.nl.config.MapOf;
|
||||||
|
import org.nl.wms.sch.task_manage.task.tasks.mapper.TestMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: lyd
|
||||||
|
* @Description: 单元测试
|
||||||
|
* @Date: 2023/5/19
|
||||||
|
*/
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
public class MapperTest {
|
||||||
|
@Autowired
|
||||||
|
private TestMapper testMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: List<HashMap<String, Object>> 等同于JSONArray
|
||||||
|
* 定义resultMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper() {
|
||||||
|
List<HashMap<String, Object>> all = testMapper.getAll();
|
||||||
|
System.out.println(all);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: JSONObject
|
||||||
|
* 定义resultMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper2() {
|
||||||
|
JSONObject all2 = testMapper.getAll2();
|
||||||
|
System.out.println(all2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: List<JSONObject> 等同JSONArray
|
||||||
|
* 定义resultMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper3() {
|
||||||
|
List<JSONObject> all3 = testMapper.getAll3();
|
||||||
|
System.out.println(all3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: JSONArray
|
||||||
|
* 每条记录类型: JSONObject
|
||||||
|
* 定义resultMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper4() {
|
||||||
|
JSONArray all4 = testMapper.getAll4();
|
||||||
|
System.out.println(all4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: JSONArray
|
||||||
|
* 每条记录类型: HashMap
|
||||||
|
* 定义resultMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper5() {
|
||||||
|
JSONArray all5 = testMapper.getAll5();
|
||||||
|
System.out.println(all5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: HashMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper6() {
|
||||||
|
HashMap<String, Object> all6 = testMapper.getAll6();
|
||||||
|
System.out.println("结果集:" + all6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: JSONObject
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper7() {
|
||||||
|
JSONObject all7 = testMapper.getAll7();
|
||||||
|
System.out.println("结果集:" + all7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: JSONArray
|
||||||
|
* 每条记录类型: JSONObject
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper8() {
|
||||||
|
JSONArray all8 = testMapper.getAll8();
|
||||||
|
System.out.println("结果集:" + all8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参查询
|
||||||
|
* 返回类型: JSONArray
|
||||||
|
* 每条记录类型: HashMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper9() {
|
||||||
|
JSONArray all9 = testMapper.getAll9();
|
||||||
|
System.out.println("结果集:" + all9);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 含参查询
|
||||||
|
* 返回类型: JSONObject
|
||||||
|
* 传参类型: HashMap
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper10() {
|
||||||
|
JSONObject all10 = testMapper.getAll10(MapOf.of("pointCode", "HNJ01"));
|
||||||
|
System.out.println("结果集:" + all10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 含参查询
|
||||||
|
* 返回类型: JSONObject
|
||||||
|
* 传参类型: JSONObject
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper11() {
|
||||||
|
//
|
||||||
|
JSONObject json=new JSONObject();
|
||||||
|
// json.put("pointCode","HNJ01");
|
||||||
|
JSONArray all11 = testMapper.getAll11(json);
|
||||||
|
System.out.println("结果集:" + all11);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mybatis - for的写法 - 使用于IN查询
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testMapper12() {
|
||||||
|
List<String> list = Arrays.asList("HNJ01", "KLHJ02");
|
||||||
|
// List<String> list = new ArrayList<>();
|
||||||
|
JSONArray all12 = testMapper.getAll12(list);
|
||||||
|
System.out.println("结果集:" + all12);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user