当前位置: 首页 > news >正文

系统之家网站怎么做中国城乡建设部官方网站

系统之家网站怎么做,中国城乡建设部官方网站,网站开发在线打开word,网站定制设计个人总结三种方式&#xff1a; Xml、queryWrapper、PageHelper第三方组件这三种方式进行查询&#xff1b; 方式一&#xff1a; xml中联表查询&#xff0c;在mapper中传参IPage<T>和条件Map&#xff08;这里用map装参数&#xff09;。 代码示例&#xff1a; Mapper层 M…

个人总结三种方式:

Xml、queryWrapper、PageHelper第三方组件这三种方式进行查询;

方式一:
xml中联表查询,在mapper中传参IPage<T>和条件Map(这里用map装参数)。

代码示例:
Mapper层
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {

IPage<UserInfo>findUserInfoByConditions(IPage<UserInfo>page,@Param("map")Map<String,Object> map);

}

Xml文件
表关系:user表id和user_scope表中user_id是主外键关系,通过这两字段关联两张表查询

<select id="findUserInfoByConditions" resultMap="UserInfoMap">
   SELECT psi.* FROM user_info ui ,user_scope us
   where ui.id=us.user_id
   <if test="map.userName != null and map.userName !='' ">
      and ui.user_name like concat('%',#{map.userName},'%')
   </if>
   <if test="map.userCoding !=null and map.userCoding!='' ">
      and ui.user_coding like concat('%',#{map.userCoding},'%')
   </if>
   <if test="map.userType != null and map.userType!='' ">
      and us.user_type like concat('%',#{map.userType},'%')
   </if>
</select>

Service层

Map map = new HashMap<>();

map.put(“userName”,”james”);

map.put(“userCoding”,”123456”);

map.put(“userType”,”普通用户”);

userInfoMapper.findUserInfoByConditions(page, map));

方式二:

PageHelper第三方组件分页查询,最后new分页对象PageInfo返回,需要注意设置分页参数和查询语句的顺序问题。
依赖引入:
<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.4.6</version>
</dependency>
代码示例:
Mapper
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {

List<UserInfo> findUserInfoList(@Param("map") Map<String,Object> map);

}

Xml

<select id="findUserInfoList" resultMap="UserInfoMap">
   SELECT psi.* FROM user_info ui ,user_scope us
   where ui.id=us.user_id
   <if test="map.userName != null and map.userName !='' ">
      and ui.user_name like concat('%',#{map.userName},'%')
   </if>
   <if test="map.userCoding !=null and map.userCoding!='' ">
      and ui.user_coding like concat('%',#{map.userCoding},'%')
   </if>
   <if test="map.userType != null and map.userType!='' ">
      and us.user_type like concat('%',#{map.userType},'%')
   </if>
</select>

Service层
int pageNumber=1;

int pageSize=10;

Map map = new HashMap<>();

map.put(“userName”,”james”);

map.put(“userCoding”,”123456”);

map.put(“userType”,”普通用户”);

PageHelper.startPage(pageNumber, pageSize);//这里顺序不能颠倒,改行必须放在查询语句前面,AOP切面编程,即动态代理模式

List<UserInfo> userInfoList = userInfoMapper.findUserInfoList(map));

PageInfo pageInfo = new PageInfo(userInfoList );//该行返回分页对象

方式三:

QueryWrapper查询方式,这里得注意联合查询时,传参的语法问题,具体见代码标记的红色部分

代码示例:

Map层
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {

IPage<UserInfo> findUserInfo(IPage<UserInfo> page,@Param(Constants.WRAPPER) QueryWrapper<UserInfo> wrappers);

}

Xml

<select id="findUserInfo" resultMap="userInfoMap">
   SELECT ui.* FROM `user_info` ui left join user_scope us
   on ui.id=us.user_id
   ${ew.customSqlSegment}//不能在此处前后加where
</select>

Service层

Int current=1;

Int size=10;

QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();

//这里注意区分是哪张表的字段,根xml里面别名对应,不然如果两张表里面有相同字段,//且出现在查询条件里面时,会分不清是具体哪张表的字段,所以一定得注明别名。

wrapper.like("ui.user_coding", “123455”);

wrapper.like("ui.user_name", “james”);

wrapper.like("us.user_type", “普通用户”)

Page<?> page = new Page<>(current, size);

userInfoMapper.findUserInfo(page, wrapper)

分析上述三种方式,就开发效率而言,方式三最快且好用,当然如果遇到业务逻辑复杂的,则可以通过xml中sql的方式来查。其实就方式三而言,如果不用QueryWrapper联表方式查询,只想用QueryWrapper的单表方式查询,可以将逻辑分层,分成两部分查询,上述三种方式,其sql都是一样的,即:
SELECT ui.* FROM `user_info` ui , user_scope us

where ui.id=us.user_id and us.user_type like '%钢%' and ui.user_name like ‘%james%’ and ui.user_coding like ‘%123%’

将该sql分成两部分:
select * from user_info where id in
(select user_id from user_scope where user_type like ‘%钢%’ )
对应QueryWrapper代码是:
wrapper.like(“user_type”,”普通用户”)
List<Object> idList = userScopeService.list(wrapper);

Wrapper.like(“user_name”,”james”);

Wrapper.like(“user_coding”,”123”);

IPage page = userInfoService.page(page,wrapper);

这样也可以达到效果,当然具体业务得具体调整拆分。如果有其他方式,你分享我整理。

http://www.yayakq.cn/news/586399/

相关文章:

  • 公司做网站入什么科目关键词包括哪些内容
  • 淘宝客做网站链接wordpress 缺少临时文件夹
  • 拖拽建站 wordpress学习软件的网站
  • 计算机一级考试网站怎么做南宁营销网站建设
  • 好用的网站开发编辑器网站文章内容排版要求
  • 做数学网站游戏推广平台有哪些
  • 装修网站建设方案百度文库一个网站的制作过程
  • 做众筹网站有哪些seo优化包括哪些
  • 竞猜网站模板videojs wordpress
  • 广州学网站开发宣传片拍摄报价明细
  • 阳谷做网站做网站的为什么那么多骗子
  • 网页设计与网站建设课程报告大学生网页设计作业教程
  • 坑梓网站建设平台中国软件公司官网
  • 上海网站建设公司地沐风wordpress
  • 网站建设教程(任务2签订网站建设合同)题库网站维护是谁做的
  • 购物网站建设成本icp网站快速备案
  • 企业网站作用网站和软件是怎么做的
  • 网站功能建设特点企业网站做口碑营销
  • 机械企业网站模板 蓝色大气 dede织梦企业模板网站开发的公司
  • 网站制作公司 知道万维科技重庆市设计院
  • 福州房地产网站建设qq腾讯官网入口
  • 网站为什么有价值是vs网站制作
  • 明年做哪些网站能致富海南智能网站建设报价
  • 用vs2010做的网站的源码深圳网站建设咨询公司
  • 大连学校网站建设html5基础知识
  • 网站字体加载不出来怎么办延边省建设局网站官网
  • 河南浪博网站开发网站建设纳千网络
  • 网上购物网站建设论文开原网站网站建设
  • 庆阳网站网站建设教你如何建网站
  • 中国建设银行网站客户注册竞馨门户网站开发