优化动态表名,扩展Mapper.xml传递动态表名
5 files added
3 files modified
| | |
| | | kidgrow.druid.loginpwd=123456 |
| | | |
| | | #eureka \u6CE8\u518C\u4E2D\u5FC3Url |
| | | kidgrow.eureka.client.serviceUrl.defaultZone=http://172.17.97.143:9001/eureka/ |
| | | kidgrow.eureka.instance.hostname=172.17.97.143 |
| | | kidgrow.eureka.client.serviceUrl.defaultZone=http://182.92.99.224:9001/eureka/ |
| | | kidgrow.eureka.instance.hostname=182.92.99.224 |
| | | ##eureka client\u53D1\u9001\u5FC3\u8DF3\u7ED9server\u7AEF\u7684\u9891\u7387 |
| | | eureka.instance.lease-renewal-interval-in-seconds=30 |
| | | #eureka client\u95F4\u9694\u591A\u4E45\u53BB\u62C9\u53D6\u670D\u52A1\u6CE8\u518C\u4FE1\u606F\uFF0C\u9ED8\u8BA4\u4E3A30\u79D2\uFF0C\u5BF9\u4E8Eapi-gateway\uFF0C\u5982\u679C\u8981\u8FC5\u901F\u83B7\u53D6\u670D\u52A1\u6CE8\u518C\u72B6\u6001\uFF0C\u53EF\u4EE5\u7F29\u5C0F\u8BE5\u503C\uFF0C\u6BD4\u59825\u79D2 |
New file |
| | |
| | | package com.kidgrow.order.controller; |
| | | |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.order.service.IOrderDetailService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: <br> |
| | | * @Project: <br> |
| | | * @CreateDate: Created in 2020/3/26 18:27 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/orderdetail") |
| | | @Api(tags = "") |
| | | public class OrderDetailController { |
| | | @Autowired |
| | | private IOrderDetailService orderDetailService; |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @ApiOperation(value = "查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping |
| | | public PageResult list(@RequestParam Map<String, Object> params) { |
| | | // DynamicTableContextHolder.setDynamicTable("order_detail_2020"); |
| | | // DynamicTableContextHolder.setDynamicTable("order_info_2020"); |
| | | |
| | | return orderDetailService.findList(params,""); |
| | | } |
| | | } |
| | |
| | | package com.kidgrow.order.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.order.entity.OrderInfoDetail; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author liuke |
| | |
| | | * @date 2019/11/22 |
| | | */ |
| | | public interface OrderInfoDetailMapper extends BaseMapper<OrderInfoDetail> { |
| | | /** |
| | | * 分页查询列表 |
| | | * @param page |
| | | * @param params |
| | | * @return |
| | | */ |
| | | List<OrderInfoDetail> findList(Page<OrderInfoDetail> page, @Param("p") Map<String, Object> params,@Param("tableTag") String tableTag); |
| | | |
| | | List<OrderInfoDetail> findListAll(Page<OrderInfoDetail> page, @Param("p") Map<String, Object> params); |
| | | } |
New file |
| | |
| | | package com.kidgrow.order.model; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.kidgrow.common.model.SuperModel; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: <br> |
| | | * @Project: <br> |
| | | * @CreateDate: Created in 2020/3/26 18:17 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @TableName("order_detail_test") |
| | | public class OrderDetail extends SuperModel { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | // |
| | | private Long testId; |
| | | // |
| | | private String name; |
| | | } |
New file |
| | |
| | | package com.kidgrow.order.service; |
| | | |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.service.ISuperService; |
| | | import com.kidgrow.order.entity.OrderInfoDetail; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: <br> |
| | | * @Project: <br> |
| | | * @CreateDate: Created in 2020/3/26 18:16 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | */ |
| | | public interface IOrderDetailService extends ISuperService<OrderInfoDetail> { |
| | | /** |
| | | * 列表 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | PageResult<OrderInfoDetail> findList(Map<String, Object> params,String tableTag); |
| | | |
| | | PageResult<OrderInfoDetail> findListAll(Map<String, Object> params); |
| | | } |
New file |
| | |
| | | package com.kidgrow.order.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.order.entity.OrderInfoDetail; |
| | | import com.kidgrow.order.mapper.OrderInfoDetailMapper; |
| | | import com.kidgrow.order.service.IOrderDetailService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: <br> |
| | | * @Project: <br> |
| | | * @CreateDate: Created in 2020/3/26 18:21 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class OrderDetailServiceImpl extends SuperServiceImpl<OrderInfoDetailMapper, OrderInfoDetail> implements IOrderDetailService { |
| | | /** |
| | | * 列表 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageResult<OrderInfoDetail> findList(Map<String, Object> params,String tableTag){ |
| | | Page<OrderInfoDetail> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit")); |
| | | List<OrderInfoDetail> list = baseMapper.findList(page, params,tableTag); |
| | | return PageResult.<OrderInfoDetail>builder().data(list).code(0).count(page.getTotal()).build(); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageResult<OrderInfoDetail> findListAll(Map<String, Object> params){ |
| | | Page<OrderInfoDetail> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit")); |
| | | List<OrderInfoDetail> list = baseMapper.findListAll(page, params); |
| | | return PageResult.<OrderInfoDetail>builder().data(list).code(0).count(page.getTotal()).build(); |
| | | } |
| | | } |
New file |
| | |
| | | <?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="com.kidgrow.order.mapper.OrderInfoDetailMapper"> |
| | | <!--定义根据-OrderDetail当作查询条件返回对象集合--> |
| | | <select id="findList" resultType="com.kidgrow.order.entity.OrderInfoDetail"> |
| | | select t.* from order_detail${tableTag} t,order_info${tableTag} s where t.order_id=s.order_id |
| | | </select> |
| | | |
| | | <select id="findListAll" resultType="com.kidgrow.order.entity.OrderInfoDetail"> |
| | | select t.* from order_detail t,order_info s where t.order_id=s.order_id |
| | | </select> |
| | | </mapper> |
| | |
| | | package com.kidgrow.order.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.kidgrow.common.context.DynamicTableContextHolder; |
| | | import com.kidgrow.order.entity.OrderInfo; |
| | | import com.kidgrow.order.service.IOrderDetailService; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.test.context.junit4.SpringRunner; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | public class OrderInfoMapperTest { |
| | | @Autowired |
| | | private OrderInfoMapper orderInfoMapper; |
| | | @Autowired |
| | | private IOrderDetailService orderDetailService; |
| | | |
| | | @Test |
| | | public void getOrderInfo(){ |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void orderDetail(){ |
| | | Map<String, Object> params=null; |
| | | params.put("page",1); |
| | | params.put("limit",10); |
| | | DynamicTableContextHolder.setDynamicTable("order_detail_2020"); |
| | | DynamicTableContextHolder.setDynamicTable("order_info_2020"); |
| | | orderDetailService.findList(params,""); |
| | | |
| | | System.out.println(orderDetailService.findList(params,"")); |
| | | |
| | | |
| | | } |
| | | } |