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

有没有关于网站开发的名人访谈桂林市区景点

有没有关于网站开发的名人访谈,桂林市区景点,cnc加工订单网,k8team wordpress1、参数获取方式 MyBatis可以通过以下两种方式获取参数值: #{变量名} 本质是占位符赋值 ${变量名} 本质是字符串拼接#xff0c;如果拼接的是字符串类型或日期类型#xff0c;则需要手动添加单引号 2、参数获取的几种情况#xff1a; 2.1 mapper接口方法的参数为单个字…1、参数获取方式 MyBatis可以通过以下两种方式获取参数值: #{变量名} 本质是占位符赋值 ${变量名} 本质是字符串拼接如果拼接的是字符串类型或日期类型则需要手动添加单引号 2、参数获取的几种情况 2.1 mapper接口方法的参数为单个字面量类型 可以通过${}和#{}以任意名称获取变量值需注意${}的单引号问题 如下 public interface UserMapper {User selectUserByUserName(String username);}select idselectUserByUserName resultTypeUser!-- select * from t_user where username ${username} --select * from t_user where username #{username}/select2.2 mapper接口方法的参数为多个时 mybatis会将多个参数封装到map集合中并以两种方式存储 方式一以arg0,arg1,arg2,…为键以参数为值方式二以param1,param2,param3,…为键以参数为值 可以通过#{}和${}两种方式以键的方式获取值即可需注意${}的单引号问题 如下 ListUser selectUserByUserNameAndAge(String username, Integer age, String sex);select idselectUserByUserNameAndAge resultTypeUser!-- select * from t_user where username ${arg0} and age ${arg1} and sex ${arg2} --select * from t_user where username #{arg0} and age #{arg1} and sex #{arg2}/select2.3 mapper接口方法有多个参数时手动封装map参数 可以通过#{}和${}两种方式以键的方式获取值即可需注意${}的单引号问题 如下 Testpublic void testQueryByMapParam(){SqlSession sqlSession SqlSessionUtil.getSqlSession();UserMapper userMapper sqlSession.getMapper(UserMapper.class);MapString, Object map new HashMap();map.put(username, 李斯);map.put(age, 23);map.put(sex, 女);ListUser admin userMapper.selectUserByMap(map);admin.stream().forEach(System.out::println);}ListUser selectUserByMap(MapString, Object map);select idselectUserByMap resultTypeUserselect * from t_user where username #{username} and age #{age} and sex #{sex}/select2.4 mapper接口方法的参数为实体类类型的参数 可以通过${}和#{}以任意名称获取变量值需注意${}的单引号问题 如下 Testpublic void testInsertUser(){SqlSession sqlSession SqlSessionUtil.getSqlSession();UserMapper userMapper sqlSession.getMapper(UserMapper.class);User user new User();user.setUsername(中华);user.setPassword(123456);user.setAge(32);user.setSex(男);int i userMapper.insertUser(user);System.out.println(i);}int insertUser(User user);insert idinsertUserinsert into t_user values(null, #{username}, #{password}, #{age}, #{sex})/insert2.5 使用Param注解命名参数 mybatis会将多个参数封装到map集合中并以两种方式存储 方式一以Param注解的值为键以参数为值方式二以param1,param2,param3,…为键以参数为值 因此可以通过${}和#{}以任意名称获取变量值需注意${}的单引号问题 Testpublic void testQueryByParam(){SqlSession sqlSession SqlSessionUtil.getSqlSession();UserMapper userMapper sqlSession.getMapper(UserMapper.class);ListUser admin userMapper.selectUserByParam(李斯, 23, 女);admin.stream().forEach(System.out::println);}ListUser selectUserByParam(Param(username) String username, Param(age) Integer age, Param(sex) String sex);select idselectUserByParam resultTypeUserselect * from t_user where username #{username} and age #{age} and sex #{sex}/select3、MyBatis参数解析原理 3.1 参数封装 主要分析MyBatis对接口参数的处理如参数的封装、参数值的获取原理。 org.apache.ibatis.reflection.ParamNameResolver#ParamNameResolverorg.apache.ibatis.reflection.ParamNameResolver#getNamedParamsParamNameResolver构造 构造方法中处理方法参数的映射建立参数的索引和参数名的映射关系。 // 参数名称处理public ParamNameResolver(Configuration config, Method method) {// 是否使用真实的参数名默认为truethis.useActualParamName config.isUseActualParamName();// 获取方法的参数类型数组final Class?[] paramTypes method.getParameterTypes();// 获取方法参数注解final Annotation[][] paramAnnotations method.getParameterAnnotations();// 存储参数信息临时对象final SortedMapInteger, String map new TreeMap();int paramCount paramAnnotations.length;// get names from Param annotationsfor (int paramIndex 0; paramIndex paramCount; paramIndex) {/**The key is the index and the value is the name of the parameter. The name is obtained from Param if specified. When Param is not specified, the parameter index is used. Note that this index could be different from the actual index when the method has special parameters (i.e. RowBounds or ResultHandler).aMethod(Param(M) int a, Param(N) int b) - {{0, M}, {1, N}}aMethod(int a, int b) - {{0, 0}, {1, 1}}aMethod(int a, RowBounds rb, int b) - {{0, 0}, {2, 1}}*/if (isSpecialParameter(paramTypes[paramIndex])) {// 跳过特殊参数 如RowBounds 或 ResultHandlercontinue;}String name null;for (Annotation annotation : paramAnnotations[paramIndex]) {if (annotation instanceof Param) {// 当前参数存在Param注解时参数名设置为注解的value值hasParamAnnotation true;name ((Param) annotation).value();break;}}if (name null) {// 如果存在Param注解且没有指定参数名if (useActualParamName) {// 取出方法参数名如果时单一普通参数则返回arg0name getActualParamName(method, paramIndex);}if (name null) {// use the parameter index as the name (0, 1, ...)// gcode issue #71// 此时将索引作为参数名name String.valueOf(map.size());}}map.put(paramIndex, name);}names Collections.unmodifiableSortedMap(map);}getNamedParams 建立参数名和参数值的映射关系并返回参数值 /*** p* A single non-special parameter is returned without a name. Multiple parameters are named using the naming rule. In* addition to the default names, this method also adds the generic names (param1, param2, ...).* /p** param args* the args** return the named params*/public Object getNamedParams(Object[] args) {final int paramCount names.size();if (args null || paramCount 0) {return null;}// 单一参数且没有Param注解时if (!hasParamAnnotation paramCount 1) {Object value args[names.firstKey()];// 此处会对集合类型的参数进行包装处理return wrapToMapIfCollection(value, useActualParamName ? names.get(names.firstKey()) : null);} else {// 建立参数名和值的映射key:参数名 value:参数值final MapString, Object param new ParamMap();int i 0;for (Map.EntryInteger, String entry : names.entrySet()) {// 1.添加命名参数和参数值的映射关系param.put(entry.getValue(), args[entry.getKey()]);// add generic param names (param1, param2, ...)final String genericParamName GENERIC_NAME_PREFIX (i 1);// ensure not to overwrite parameter named with Paramif (!names.containsValue(genericParamName)) {// 2.同时添加一个以param1,param2...为参数名 和 参数值的映射关系param.put(genericParamName, args[entry.getKey()]);}i;}return param;}}wrapToMapIfCollection /*** Wrap to a {link ParamMap} if object is {link Collection} or array.** param object* a parameter object* param actualParamName* an actual parameter name (If specify a name, set an object to {link ParamMap} with specified name)** return a {link ParamMap}** since 3.5.5*/public static Object wrapToMapIfCollection(Object object, String actualParamName) {// 如果是集合类型则包装key为collection、list的map返回if (object instanceof Collection) {ParamMapObject map new ParamMap();map.put(collection, object);if (object instanceof List) {map.put(list, object);}Optional.ofNullable(actualParamName).ifPresent(name - map.put(name, object));return map;}// 如果是数据组类型则包装key为array的map返回if (object ! null object.getClass().isArray()) {ParamMapObject map new ParamMap();map.put(array, object);Optional.ofNullable(actualParamName).ifPresent(name - map.put(name, object));return map;}// 如果不是集合类型或数组类型则直接返回当前值return object;}3.2 参数调用 在org.apache.ibatis.binding.MapperMethod#execute方法中通过convertArgsToSqlCommandParam获取参数值。 public Object execute(SqlSession sqlSession, Object[] args) {Object result;switch (command.getType()) {case INSERT: {Object param method.convertArgsToSqlCommandParam(args);result rowCountResult(sqlSession.insert(command.getName(), param));break;}case UPDATE: {Object param method.convertArgsToSqlCommandParam(args);result rowCountResult(sqlSession.update(command.getName(), param));break;}case DELETE: {Object param method.convertArgsToSqlCommandParam(args);result rowCountResult(sqlSession.delete(command.getName(), param));break;}case SELECT:if (method.returnsVoid() method.hasResultHandler()) {executeWithResultHandler(sqlSession, args);result null;} else if (method.returnsMany()) {result executeForMany(sqlSession, args);} else if (method.returnsMap()) {result executeForMap(sqlSession, args);} else if (method.returnsCursor()) {result executeForCursor(sqlSession, args);} else {// 获取参数值Object param method.convertArgsToSqlCommandParam(args);result sqlSession.selectOne(command.getName(), param);if (method.returnsOptional() (result null || !method.getReturnType().equals(result.getClass()))) {result Optional.ofNullable(result);}}break;case FLUSH:result sqlSession.flushStatements();break;default:throw new BindingException(Unknown execution method for: command.getName());}if (result null method.getReturnType().isPrimitive() !method.returnsVoid()) {throw new BindingException(Mapper method command.getName() attempted to return null from a method with a primitive return type ( method.getReturnType() ).);}return result;}
http://www.pierceye.com/news/489095/

相关文章:

  • 做网站 侵权做外贸怎么看外国网站
  • 网站建设知识点的总结普通网站建设是什么
  • 杭州网站建设费用多少合肥高新城建设计院网站
  • 炫酷特效网站asa8.4 做网站映射
  • 郑州租赁房网站建设九江快乐城
  • 手机网站建站教育模板微信网站 教程
  • 网站的结构犀牛云做网站多少钱
  • 网站服务器用什么配置公司网站建设的视频教程
  • idea做网站网络营销与网站推广的区别
  • 建一家网站多少钱微信小程序在哪里查找
  • 东阳网站推广英文网站源码下载
  • 介绍湛江网站高端网站建设网站定制
  • 网站的特征包括哪些方面wordpress缓存插件 w3
  • 东莞专业网站营销wordpress新建页面模板
  • 做外贸学习网站智慧团建网页电脑版登录网站
  • 如何免费做一个网站攻略常州网站推广软件
  • 手机网站建站 服务器网站名称收录
  • 网站根 html网站建设 永灿 竞争
  • 网站建设费合同天津网站建设公司
  • 自己怎么做优惠卷网站购物网站建设需求模板下载
  • 上海智能网站建设公司可以做网站头像的图片
  • 怎样给网站做备案网站建设前端工程师岗位职责
  • 福州网站外包网站搭建设计合同
  • 有没有做专利导航运营的网站网站制作代理
  • 即墨网站建设地址邢台织梦模板建站
  • 贵阳网站建设运营网站的扁平化设计理念
  • 商务网站建设与维护(专21春)网站建设入门书籍
  • 免费室内设计素材网站wordpress 前台不显示内容
  • 企业应该找什么样的网站建设公司jz做网站
  • 钦州住房和城乡建设局网站软考考试科目有哪些