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

做违法网站会怎样外贸独立站怎么建站

做违法网站会怎样,外贸独立站怎么建站,北京免费建站模板,极速网站推广专家个人总结三种方式&#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.hkea.cn/news/489344/

相关文章:

  • 云主机建网站教程深圳全网推互联科技有限公司
  • 做网站赚50万谷歌搜索引擎363入口
  • 台州网站设计外包网页制作公司排名
  • 网站建设投标文件范本亚马逊提升关键词排名的方法
  • 学做网站需要多长时间免费推广平台排行
  • wordpress运行php 404360优化大师下载
  • seo排名网站 优帮云线上推广的三种方式
  • 平凉哪有做网站的百度推广登录入口官网网
  • 娄底网站优化自建网站平台有哪些
  • 做网站需要多少兆空间wix网站制作
  • 哪些网站教做生物实验今日新闻联播
  • 铜川市住房和城乡建设局网站信息流广告哪个平台好
  • 太原市建设交易中心网站首页百度手机助手app安卓版官方下载
  • 昆山网站建设网站建设郑州网络推广哪个好
  • 瑜伽网站设计国外推广网站
  • 什么网站做国外批发百度推广自己怎么做
  • 网站管理工具百度推广可以自己开户吗
  • 三水网站制作中山做网站推广公司
  • ysl网站设计论文郑州seo地址
  • 做食品的网站设计要注意片多多可以免费看电视剧吗
  • 网站排名推广自己怎么做长沙seo代理商
  • 手机网站改版公司加盟关键词优化排名查询
  • html5 图片网站建设企业网站多少钱
  • 企业网站定制开发流程网络营销的概念及特点
  • 做火影网站背景图农村电商平台有哪些
  • 国内html5网站建设seo兼职工资一般多少
  • 青海西宁网站建设公司百度网络推广
  • 服装公司网站设计百度站长收录入口
  • 做搜索关键词任务网站网站维护是什么意思
  • 2018什么做网站百度网盘网页版入口