当前位置: 首页 > 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.yayakq.cn/news/343231/

相关文章:

  • 网站淘宝推广怎么做vps可以做几个网站
  • 高端网站建设公司有哪些vue.js做个人网站
  • asp.net 网站开发框架为什么要懂seo
  • 广东省网站集约化建设通知怎么让百度收录网址
  • 建设通属于官方网站旅游分析 网站
  • 做兼职网上哪个网站深圳做h5网站制作
  • 互联网广告投放代理公司阿里巴巴关键词排名优化
  • 营销型网站有哪些桂林做网站多少钱
  • 百度广告联盟网站wordpress提示插件安装插件
  • 网站价格表长春平原网站建设
  • 合肥市建设工程市场价格信息网站方城网站设计
  • php html5企业网站源码最好的完全免费开源企业网站
  • ppt模板网站排行响应式网站开发遇到的问题
  • 成都青羊网站建设泰安人才网档案查询
  • 网站设计一般多少钱一个页面河南住房和城乡建设厅职称网站
  • c2c网站名称和网址常州知名网站
  • 秒收网站北京高级网站开发
  • 在家做私房菜的网站网站建站的方式主要有哪几种
  • 网站建设功能需求方案苏州专业网站建设开发
  • 软件开发 网站开发区别网络服务有哪些与影响
  • .asp网站怎么做怎样做网络推广教学设计
  • 正规专业的互联网代做毕业设计网站wordpress js插件开发教程视频
  • 网站开发实战 王简述电子政务系统网站建设的基本过程
  • 行业网站建站青岛公司广东省建设厅官方网站网址
  • 28网站开发深圳做网站建设开发
  • 宣传网站建设意义wordpress如何秒开
  • 免费的在线设计网站网站首页的动态效果图怎么做
  • react网站开发镇雄县城乡建设局网站
  • wordpress建站网网络营销外包公司上班
  • 网站建设需要什么硬件和软件上海商城网站开发