Springboot+Mybatis简单查询
2017-10-17 10:54
555 查看
1.ChannelListMapper.xml<?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.ysotek.wms.microservice.infrastructure.mapper.impl.tnb.ChannelListMapper"><resultMap id="ListResultMap" type="com.ysotek.wms.microservice.model.infrastructure.vo.tnb.ChannelBaseVO"><id column="channel_id" jdbcType="BIGINT" property="channelId" /><result column="channel_name_cn" jdbcType="VARCHAR" property="channelNameCn" /><result column="parent_owner_name" jdbcType="VARCHAR" property="parentOwnerName" /><result column="channel_tel" jdbcType="VARCHAR" property="channelTel" /><result column="channel_email" jdbcType="VARCHAR" property="channelEmail" /><result column="link_man" jdbcType="VARCHAR" property="linkMan" /><result column="create_date" jdbcType="TIME" property="createDate" /></resultMap><resultMap id="BaseResultMap" type="com.ysotek.wms.microservice.model.infrastructure.vo.tnb.ChannelListVO"><id column="channel_id" jdbcType="BIGINT" property="channelId" /><result column="channel_name_cn" jdbcType="VARCHAR" property="channelNameCn" /><result column="channel_name_en" jdbcType="VARCHAR" property="channelNameEn" /><result column="activity_true" jdbcType="TINYINT" property="activityTrue" /><result column="invoice_desc" jdbcType="VARCHAR" property="invoiceDesc" /><result column="fee_rate" jdbcType="DOUBLE" property="feeRate" /><result column="channel_tel" jdbcType="VARCHAR" property="channelTel" /><result column="channel_fax" jdbcType="VARCHAR" property="channelFax" /><result column="channel_web" jdbcType="VARCHAR" property="channelWeb" /><result column="channel_email" jdbcType="VARCHAR" property="channelEmail" /><result column="link_man" jdbcType="VARCHAR" property="linkMan" /><result column="channel_province" jdbcType="VARCHAR" property="channelProvince" /><result column="channel_city" jdbcType="VARCHAR" property="channelCity" /><result column="channel_area" jdbcType="VARCHAR" property="channelArea" /><result column="channel_address" jdbcType="VARCHAR" property="channelAddress" /><result column="channel_true" jdbcType="TINYINT" property="channelTrue" /><result column="consignee_true" jdbcType="TINYINT" property="consigneeTrue" /><result column="deliver_true" jdbcType="TINYINT" property="deliverTrue" /><result column="property" jdbcType="VARCHAR" property="property" /><result column="create_date" jdbcType="TIME" property="createDate" /><result column="update_date" jdbcType="TIME" property="updateDate" /><result column="parent_owner_name" jdbcType="VARCHAR" property="parentOwnerName" /></resultMap><sql id="Base_Column_List">c.channel_id,c.channel_name_cn,c.channel_name_en,c.activity_true,c.invoice_desc,c.fee_rate,c.channel_tel,c.channel_fax,c.channel_web,c.channel_email,c.link_man,c.channel_province,c.channel_city,c.channel_area,c.channel_address,c.channel_true,c.consignee_true,c.deliver_true,c.property,c.create_date,c.update_date,p.parent_owner_name</sql><select id="getList" resultMap="ListResultMap">selectc.channel_id,c.channel_name_cn,p.parent_owner_name,c.channel_tel,c.channel_email,c.link_man,c.create_datefrom wms_basic_channel as cleft join wms_basic_parent_owner as pon c.belong_parent_owner_id=p.parent_owner_idwhere 1 = 1ORDER BY c.create_date DESClimit #{from},#{to}</select><select id="getCount" resultType="Long">select count(c.channel_id)from wms_basic_channel as c</select><select id="getChannelsList" resultMap="BaseResultMap">selectc.channel_id,c.channel_name_cn,c.channel_name_en,c.activity_true,c.invoice_desc,c.fee_rate,c.channel_tel,c.channel_fax,c.channel_web,c.channel_email,c.link_man,c.channel_province,c.channel_city,c.channel_area,c.channel_address,c.channel_true,c.consignee_true,c.deliver_true,c.property,c.create_date,c.update_date,p.parent_owner_namefrom wms_basic_channel as cleft join wms_basic_parent_owner as pon c.belong_parent_owner_id=p.parent_owner_idwhere 1 = 1<if test="channelId != null and channelId != ''">AND c.channel_id = #{channelId}</if><if test="channelNameCn != null and channelNameCn != ''">AND c.channel_name_cn like #{channelNameCn}</if>ORDER BY c.create_date DESC</select></mapper>
2.实体类:ChannelBaseVO.java,ChannelListVO.java
@Data可以直接建getset方法
package com.ysotek.wms.microservice.model.infrastructure.vo.tnb; import com.ysotek.wms.microservice.model.infrastructure.vo.IChannelBaseVO; import lombok.Data; import java.util.Date; /** * Created by Cherry on 0013 13 十月. */ public @Data class ChannelBaseVO implements IChannelBaseVO { Long channelId; String channelNameCn; String parentOwnerName; String channelTel; String channelEmail; String linkMan; Date createDate; }
package com.ysotek.wms.microservice.model.infrastructure.vo.tnb; import com.ysotek.wms.microservice.model.infrastructure.vo.IChannelListVO; import lombok.Data; import java.util.Date; /** * Created by Cherry on 0012 12 十月. */ public @Data class ChannelListVO implements IChannelListVO { Long channelId; String channelNameCn; String channelNameEn; String parentOwnerName; boolean activityTrue; String invoiceDesc; Double feeRate; String channelTel; String channelFax; String channelWeb; String channelEmail; String linkMan; String channelProvince; String channelCity; String channelArea; String channelAddress; boolean channelTrue; boolean consigneeTrue; boolean deliverTrue; String property; Date createDate; Date updateDate; }
package com.ysotek.wms.microservice.model.infrastructure.vo; /** * Created by Cherry on 0013 13 十月. */ public interface IChannelBaseVO { }
package com.ysotek.wms.microservice.model.infrastructure.vo; /** * Created by Cherry on 0012 12 十月. */ public interface IChannelListVO { }
3.Dao数据层:ChannelListMapper.java
package com.ysotek.wms.microservice.infrastructure.mapper.impl.tnb;import com.ysotek.wms.microservice.infrastructure.mapper.impl.IChannelListMapper;import org.springframework.stereotype.Component;/*** Created by Cherry on 0012 12 十月.*/@Component("TnbChannelListMapper")public interface ChannelListMapper<T> extends IChannelListMapper<T> {}
package com.ysotek.wms.microservice.infrastructure.mapper.impl;import java.util.List;import java.util.Map;/*** Created by Cherry on 0012 12 十月.*/public interface IChannelListMapper<T> {List<T> getList(Map<String, Object> map);Long getCount(Map<String, Object> map);List<T> getChannelsList(Map<String, Object> map);}
4.service层ChannelServiceImpl.java
package com.ysotek.wms.microservice.infrastructure.service.impl.tnb;import com.ysotek.wms.microservice.core.model.PageModel;import com.ysotek.wms.microservice.infrastructure.mapper.impl.IChannelListMapper;import com.ysotek.wms.microservice.infrastructure.service.IChannelService;import com.ysotek.wms.microservice.model.infrastructure.vo.IChannelListVO;import org.springframework.beans.factory.annotation.Autowired;import org.springbeecframework.beans.factory.annotation.Qualifier;import org.springframework.stereotype.Service;import java.util.List;import java.util.Map;/*** Created by Cherry on 0012 12 十月.*/@Service("TnbChannelService")public class ChannelServiceImpl implements IChannelService{@Autowired@Qualifier(value = "TnbChannelListMapper")IChannelListMapper<IChannelListVO> channelListMapper;@Overridepublic PageModel queryChannels(Map<String, Object> map) {List result=channelListMapper.getList(map);Long total=channelListMapper.getCount(map);return new PageModel(total,result);}@Overridepublic List<IChannelListVO> queryChannelsList(Map<String, Object> map) {return channelListMapper.getChannelsList(map);}@Overridepublic void createChannel() {}}
package com.ysotek.wms.microservice.infrastructure.service.impl.tnb;import com.ysotek.wms.microservice.core.model.PageModel;import com.ysotek.wms.microservice.infrastructure.mapper.impl.IChannelListMapper;import com.ysotek.wms.microservice.infrastructure.service.IChannelService;import com.ysotek.wms.microservice.model.infrastructure.vo.IChannelListVO;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.stereotype.Service;import java.util.List;import java.util.Map;/*** Created by Cherry on 0012 12 十月.*/@Service("TnbChannelService")public class ChannelServiceImpl implements IChannelService{@Autowired@Qualifier(value = "TnbChannelListMapper")IChannelListMapper<IChannelListVO> channelListMapper;@Overridepublic PageModel queryChannels(Map<String, Object> map) {List result=channelListMapper.getList(map);Long total=channelListMapper.getCount(map);return new PageModel(total,result);}@Overridepublic List<IChannelListVO> queryChannelsList(Map<String, Object> map) {return channelListMapper.getChannelsList(map);}@Overridepublic void createChannel() {}}5.Api控制层:InfrastructureAPI.java
package com.ysotek.wms.microservice.infrastructure.api;import com.ysotek.wms.microservice.core.logging.LogSource;import com.ysotek.wms.microservice.core.logging.WMSLogger;import com.ysotek.wms.microservice.core.model.ApiReturnModel;import com.ysotek.wms.microservice.core.model.PageModel;import com.ysotek.wms.microservice.infrastructure.service.IChannelService;import com.ysotek.wms.microservice.model.infrastructure.vo.IChannelListVO;import org.apache.commons.lang.StringUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.web.bind.annotation.*;import java.util.HashMap;import java.util.List;import java.util.Map;@RestController@RequestMapping( path = {"/api/tnb/infrastructure", "/api/dev/infrastructure","/api/demo/infrastructure"})public class InfrastructureAPI {@Autowired@Qualifier(value = "TnbChannelService")IChannelService channelService;/***查询渠道商*/@RequestMapping(value = "/channel", method = {RequestMethod.GET})@ResponseBodypublic ApiReturnModel queryChannel(@RequestParam(required = false) Integer from,@RequestParam(required = false) Integer to,@RequestParam(required = false) Integer page,@RequestParam(required = false) Integer rows){WMSLogger.trace(LogSource.CHANNEL_QUERY,String.format("渠道商查询开始"));Map<String, Object> map = new HashMap<String, Object>();if (rows == null){rows = 20;}if (from == null){if (page == null){map.put("from",0);}else{from = (page - 1) * rows;map.put("from",from);}}else{map.put("from",from);}if (to == null){map.put("to",rows);}else{map.put("to",to);}PageModel result = channelService.queryChannels(map);WMSLogger.trace(LogSource.CHANNEL_QUERY, String.format("渠道商查询结束,结果条数 %s",result.getTotalNum()));return new ApiReturnModel(200,result);}/*** 根据id或name查询渠道商* @param channelNameCn* @return*/@RequestMapping(value = "/channels", method = {RequestMethod.GET})@ResponseBodypublic ApiReturnModel queryChannelDetailByName(@RequestParam(required = false) String channelId,@RequestParam(required = false) String channelNameCn){WMSLogger.trace(LogSource.CHANNEL_QUERY,String.format("单个渠道商查询开始,参数channelId:%s,channelNameCn:%s",channelId,channelNameCn));Map<String, Object> map = new HashMap<String, Object>();if (StringUtils.isNotBlank(channelId)){map.put("channelId", channelId);}if (StringUtils.isNotBlank(channelNameCn)){map.put("channelNameCn", "%"+channelNameCn+"%");}List<IChannelListVO> channelListVOList=channelService.queryChannelsList(map);if (channelListVOList == null){return new ApiReturnModel<String>(203,"订单不存在");}return new ApiReturnModel(200,channelListVOList);}@RequestMapping(method = {RequestMethod.POST})@ResponseBodypublic ApiReturnModel create(){return null;}}
相关文章推荐
- SpringBoot中使用Spring Data Jpa 实现简单的动态查询的两种方法
- Springboot+mybatis+Jsp+ztree2.5简单的小demo
- 简单快速的用SpringBoot集成多数据源(mybatis)
- 使用Spring Boot+MyBatis框架做查询操作
- SpringBoot简单连接数据库以及查询数据
- [置顶] 【二】Springboot+Mybatis+Redis实现用户信息查询缓存
- 【第十一章】 springboot + mongodb(简单查询)
- springboot+mybatis+springmvc+mysql简单项目
- springboot + mybatis-pagehelper 参数查询不分页的bug。。。
- spring boot + mybatis简单操作
- 利用struts2,mybatis,spring,三大框架写的一个简单的查询程序
- Springboot+mybatis搭建(以尽可能简单的,外加注释的方式)
- springboot整合mybatis一个简单的demo
- SpringCloud SpringBoot mybatis 分布式微服务(九)Spring Boot中使用Spring-data-jpa让数据访问更简单
- 详细步骤!!!idea+springboot+mybatis+jsp+bootstrap实现从mysql查询出数据并显示(源码)
- SpringBoot使用Mybatis注解进行一对多和多对多查询
- springboot+mybatis MyBatis查询返回Map时设置值为null的字段没有在结果集中
- eclipse搭建简单springboot-mybatis项目实现页面简单跳转
- springboot+mybatis日志显示SQL的最简单方法
- Spring Boot(1)集成MyBatis的简单使用