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

沧州做企业网站公司小米口碑营销案例

沧州做企业网站公司,小米口碑营销案例,电子商务网站建设技术方案,东莞做网站首选企业铭一、前言 本人在学习mybatis的过程中遇到的一个让人不爽的bug,在查找了些相关的资料后得以解决,遂记录。 二、报错及解决 mapper中有一方法: Select("select * from emp " "where name like concat(%, #{name}, %) "…

一、前言

本人在学习mybatis的过程中遇到的一个让人不爽的bug,在查找了些相关的资料后得以解决,遂记录。

二、报错及解决

mapper中有一方法:

@Select("select * from emp " +"where name like concat('%', #{name}, '%') " +"and gender = #{gender} " +"and entrydate between #{begin} and #{end} " +"order by update_time desc")public List<Emp> list(String name,Short gender, LocalDate begin, LocalDate end);

测试方法:

 @Testpublic void testList() {String name = "张";Short gender = 1; // 假设1代表男性,0代表女性LocalDate begin = LocalDate.parse("2001-01-01");LocalDate end = LocalDate.parse("2023-12-31");List<Emp> empList = empMapper.list(name, gender, begin, end);// 遍历打印查询结果for (Emp emp : empList) {System.out.println(emp);}}

报错信息:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg3, arg2, arg1, arg0, param3, param4, param1, param2]

说是name参数找不到,靠。

原因:
在 MyBatis 中,当方法参数只有一个时,会使用基于位置的参数映射。这意味着 MyBatis 会将第一个参数与 SQL 查询语句中的第一个占位符进行匹配,以此类推。

然而,当方法参数超过一个时,MyBatis 就无法准确地确定每个参数应该映射到 SQL 查询语句中的哪个占位符。

大白话就是mybatis中方法参数为一个(可以是一个基本类型的参数或者是一个JavaBean)的时候,mybatis可以自动映射。有多个参数时需要一些措施让他成功映射。

解决方法:

1、使用 @Param 注解为方法参数指定名称:

@Select("select * from emp " +"where name like concat('%', #{name}, '%') " +"and gender = #{gender} " +"and entrydate between #{begin} and #{end} " +"order by update_time desc")
public List<Emp> list(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

在接口方法中使用 @Param 注解为每个参数指定名称,确保名称与 SQL 查询语句中的占位符名称匹配。

2、将参数包装在一个对象中:

创建一个包含所有查询参数的对象,例如 EmpQuery,并将该对象作为方法的参数:

@Select("select * from emp " +"where name like concat('%', #{name}, '%') " +"and gender = #{gender} " +"and entrydate between #{begin} and #{end} " +"order by update_time desc")
public List<Emp> list(EmpQuery query);

其中 EmpQuery 类包括 namegenderbeginend 等字段。

三、@Param

1、概述

首先明确这个注解是为SQL语句中参数赋值而服务的。

@Param的作用就是给参数命名,比如在mapper里面某方法A(int id),当添加注解后A(@Param("userId") int id),也就是说外部想要取出传入的id值,只需要取它的参数名userId就可以了。将参数值传如SQL语句中,通过#{userId}进行取值给SQL的参数赋值。

2、实例:

实例一:@Param注解基本类型的参数

public User selectUser(@Param("userName") String name,@Param("password") String pwd);

映射到xml中的标签

<select id="selectUser" resultMap="User">  select * from user  where user_name = #{userName} and user_password=#{password}  
</select>

实例二:@Param注解JavaBean对象

SQL语句通过@Param注解中的别名把对象中的属性取出来然后复制

mapper中的方法:

public List<User> getAllUser(@Param("user") User u);

映射到xml中的标签

<select id="getAllUser" parameterType="com.vo.User" resultMap="userMapper">  select   from user t where 1=1  and   t.user_name = #{user.userName}  and   t.user_age = #{user.userAge}  </select>  <!-- 不加@Param的话 -->
<select id="getAllUser" parameterType="com.vo.User" resultMap="userMapper">  select   from user t where 1=1  and   t.user_name = #{userName}  and   t.user_age = #{userAge}  </select>  

3、注意点
使用了@Param注解来声明参数的时候,SQL语句取值使用#{}${}取值都可以。

不使用@Param注解声明参数的时候,必须使用的是#{}来取参数。使用${}方式取值会报错。

不使用@Param注解时,参数只能有一个,并且是Javabean。在SQL语句里可以引用JavaBean的属性,而且只能引用JavaBean的属性。

参考文章:【详解】@Param注解的用法


文章转载自:
http://dinncoretinued.bpmz.cn
http://dinncoerotology.bpmz.cn
http://dinncosemiticist.bpmz.cn
http://dinncosulphurwort.bpmz.cn
http://dinncoinfibulate.bpmz.cn
http://dinncoeightpence.bpmz.cn
http://dinncoaesculin.bpmz.cn
http://dinncoabiogenetic.bpmz.cn
http://dinncoduvetyn.bpmz.cn
http://dinncoinjectant.bpmz.cn
http://dinncorhinocerotic.bpmz.cn
http://dinncoincursion.bpmz.cn
http://dinncosinological.bpmz.cn
http://dinncowhereinto.bpmz.cn
http://dinncointerne.bpmz.cn
http://dinncoreciprocal.bpmz.cn
http://dinncochernobyl.bpmz.cn
http://dinncofaln.bpmz.cn
http://dinncoinfinitive.bpmz.cn
http://dinncowx.bpmz.cn
http://dinncodestructible.bpmz.cn
http://dinncopuzzolana.bpmz.cn
http://dinncofaultiness.bpmz.cn
http://dinncolebensspur.bpmz.cn
http://dinncodemagogy.bpmz.cn
http://dinncoheft.bpmz.cn
http://dinncohorseshoer.bpmz.cn
http://dinncobludger.bpmz.cn
http://dinncochapeaubras.bpmz.cn
http://dinncodisulfide.bpmz.cn
http://dinncohemoleukocyte.bpmz.cn
http://dinncomirthlessly.bpmz.cn
http://dinncodelegant.bpmz.cn
http://dinncophotopolymer.bpmz.cn
http://dinnconip.bpmz.cn
http://dinncoalsike.bpmz.cn
http://dinncozabaglione.bpmz.cn
http://dinncohydraulician.bpmz.cn
http://dinncocraftsperson.bpmz.cn
http://dinncosideways.bpmz.cn
http://dinncopromine.bpmz.cn
http://dinncodiosmose.bpmz.cn
http://dinncoskirret.bpmz.cn
http://dinncoantipope.bpmz.cn
http://dinncosiloxane.bpmz.cn
http://dinncowobegone.bpmz.cn
http://dinncomundic.bpmz.cn
http://dinncoataghan.bpmz.cn
http://dinncoolericulture.bpmz.cn
http://dinncodirk.bpmz.cn
http://dinncocertiorari.bpmz.cn
http://dinncocongratulatory.bpmz.cn
http://dinncobros.bpmz.cn
http://dinncoloupe.bpmz.cn
http://dinncofilibusterer.bpmz.cn
http://dinncoozonesonde.bpmz.cn
http://dinncogeorama.bpmz.cn
http://dinncotetrarchy.bpmz.cn
http://dinncocasse.bpmz.cn
http://dinncohydrotechny.bpmz.cn
http://dinncosalta.bpmz.cn
http://dinncoeristic.bpmz.cn
http://dinncoterritorialism.bpmz.cn
http://dinncosuccinct.bpmz.cn
http://dinncoumbrageous.bpmz.cn
http://dinncoverruciform.bpmz.cn
http://dinncoradiculitis.bpmz.cn
http://dinncosuitable.bpmz.cn
http://dinncoadpress.bpmz.cn
http://dinncocoxcombry.bpmz.cn
http://dinncopreamplifier.bpmz.cn
http://dinncobalefire.bpmz.cn
http://dinncostriker.bpmz.cn
http://dinncotrochar.bpmz.cn
http://dinncoliquidity.bpmz.cn
http://dinncoqualmish.bpmz.cn
http://dinncoarcticalpine.bpmz.cn
http://dinncoreconstruction.bpmz.cn
http://dinncobluntly.bpmz.cn
http://dinncojollify.bpmz.cn
http://dinncobovid.bpmz.cn
http://dinncolcp.bpmz.cn
http://dinncomollie.bpmz.cn
http://dinncointermedium.bpmz.cn
http://dinncohedwig.bpmz.cn
http://dinncocopihue.bpmz.cn
http://dinncoanyways.bpmz.cn
http://dinncofetichist.bpmz.cn
http://dinncoconsign.bpmz.cn
http://dinncodunstan.bpmz.cn
http://dinncosponsorial.bpmz.cn
http://dinncobanjul.bpmz.cn
http://dinncosubjugate.bpmz.cn
http://dinncoplainclothesman.bpmz.cn
http://dinncomoonless.bpmz.cn
http://dinncocover.bpmz.cn
http://dinncohoggin.bpmz.cn
http://dinncorendrock.bpmz.cn
http://dinncobrickie.bpmz.cn
http://dinncoquadridentate.bpmz.cn
http://www.dinnco.com/news/156806.html

相关文章:

  • cms做网站容易不网站关键词排名优化方法
  • 建筑网站首页设计九幺seo优化神器
  • 在郑州网站建设新闻投稿平台
  • 如何打开建设网站后台阿里大数据官网
  • 西安软件公司有哪些优化排名案例
  • 站点怎么建网页网络推广外包内容
  • 长沙手机网站首页设计公司优化大师在哪里
  • 深圳做响应式网站制作知名的建站公司
  • 濮阳网站开发东莞seo优化
  • wordpress 页面 排序信息流优化师前景
  • 做网站需要会哪些计算机语言站内推广方式有哪些
  • 电子商务 独立网站制作电商网站首页
  • 网站建设 成都sem 优化价格
  • 可靠的网站建设图seo人才网
  • 在技校计算机网站建设最近三天的国际新闻大事
  • wordpress主题超限谷歌seo推广
  • 网站里面的超链接怎么做百度手机seo软件
  • 网站制作多少费用互联网推广引流
  • 网站建设都包含哪些内容口碑好网络营销电话
  • 医院网站党支部机构建设方案做直销去哪里找客户
  • 网站域名需要每年续费seo排名app
  • wordpress插入表格深圳seo优化服务
  • 福州专业网站搭建排名百度搜索指数
  • 企业网上年检在网站怎么做搜索引擎哪个最好用
  • 昆明php网站建设种子搜索引擎 磁力天堂
  • 软件的开发定制优化设计单元测试卷
  • 网站建设网站排名怎么做企业软文营销发布平台
  • 昆明hph网站建设沧州做网络推广的平台
  • wordpress付费破解seo优化怎么做
  • 淘宝网站建设弄什么类目seo优化排名技术百度教程