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

番禺外贸型网站建设做头条信息流要网站吗

番禺外贸型网站建设,做头条信息流要网站吗,制作单位网站,网站建设方案备案day72 mybatis mybatis的实现方式 三种实现方式#xff1a; 纯xml方式#xff0c;namespace随便写#xff0c;id随便写#xff0c;只要保证整个项目namespaceid唯一即可 xml接口的方式#xff0c;namespace必须是接口的全路径#xff0c;id必须是接口的方法名#xf…day72 mybatis mybatis的实现方式 三种实现方式 纯xml方式namespace随便写id随便写只要保证整个项目namespaceid唯一即可 xml接口的方式namespace必须是接口的全路径id必须是接口的方法名结合第一种方式接口中不允许存在重载的方法 纯注解方式注册时需要在mybatis的核心配置文件中设置mapper的class或者mappers下面配置package xml接口方式 ?xml version1.0 encodingUTF-8 ? !DOCTYPE configurationPUBLIC -//mybatis.org//DTD Config 3.0//ENhttps://mybatis.org/dtd/mybatis-3-config.dtd configuration ​settings!--日志实现--setting namelogImpl valueSTDOUT_LOGGING//settings ​environments defaultdevelopmentenvironment iddevelopmenttransactionManager typeJDBC/dataSource typePOOLEDproperty namedriver valuecom.mysql.jdbc.Driver/property nameurl valuejdbc:mysql://localhost:3306/mi?useSSLfalseamp;characterEncodingUTF-8/property nameusername valueroot/property namepassword valueAbc1234//dataSource/environment/environmentsmappersmapper resourcecom/saas/dao/ProductsMapper.xml/ !--       mapper classcom.saas.dao.IProductDaoAnnotation/-- !--       package namecom.saas.dao/--/mappers /configuration 在mybatis-config的核心配置文件中设置mappers节点里面放mapper节点mapper标签中使用resource属性加入xml文件路径 package com.saas.pojo; ​ import lombok.Data; ​ Data public class Product {private int cid     ;private String title   ;private String subtitle;private String wtype   ;private String img     ;private String cdesc   ;private double oprice ;private double nprice ;private int tid     ; } package com.saas.dao; ​ import com.saas.pojo.Product; ​ import java.util.List; ​ public interface IProductDao { ​ListProduct getAllProducts(); ​Product getProductById(int i); ​int updateProduct(Product product); } ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttps://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.saas.dao.IProductDaoselect idgetAllProducts resultTypecom.saas.pojo.Productselect * from products/select ​select idgetProductById resultTypecom.saas.pojo.Productselect * from products where cid #{cid}/select ​update idupdateProductupdate products set title #{title}, subtitle #{subtitle}, wtype #{wtype} , img #{img} ,cdesc #{cdesc} , oprice #{oprice}, nprice #{nprice}, tid #{tid} where cid #{cid}/update /mapper 这里要特别注意 namespace必须是接口的全路径 id必须是接口中的每个方法的方法名 由于之前mybatis中不能存在同namespaceid的场景所以接口中不允许存在重载方法 package com.saas.dao; ​ import com.saas.pojo.Product; import com.saas.util.SessionUtil; import org.apache.ibatis.session.SqlSession; import org.junit.Test; ​ import java.util.List; ​ public class TestProducts { ​private SqlSession session null; ​Testpublic void testGetAllProducts() { ​session SessionUtil.getSession(); ​IProductDao iProductDao session.getMapper(IProductDao.class); ​ListProduct list iProductDao.getAllProducts(); ​for (Product p : list) {System.out.println(p);} ​SessionUtil.closeSession(session);} ​Testpublic void testGetProductById() {session SessionUtil.getSession();IProductDao iProductDao session.getMapper(IProductDao.class);Product product iProductDao.getProductById(1);System.out.println(product);SessionUtil.closeSession(session);} ​Testpublic void testUpdateProduct() {session SessionUtil.getSession();IProductDao iProductDao session.getMapper(IProductDao.class); ​Product product new Product();product.setCid(3);product.setTitle(iphone);product.setOprice(16999);product.setNprice(12999);product.setCdesc(iphone 15);product.setTid(1);product.setSubtitle(iphone15promax);product.setImg(ip15.jpg);product.setWtype(taobao); ​int i iProductDao.updateProduct(product); ​System.out.println(i 0); ​SessionUtil.closeSession(session);} } 这里注意我们需要结束SqlSession对象的getMapper方法方法参数设置接口的类对象来得到接口对象 一旦有了接口对象则借助该接口对象调用接口中的方法即可完成所有的crud功能 测试完成其crud功能 纯注解方式 按照之前两种方式最直接的结果是每个crud方法最终都对应一个正确的SQL语句即可所以注解方式更“直接” ?xml version1.0 encodingUTF-8 ? !DOCTYPE configurationPUBLIC -//mybatis.org//DTD Config 3.0//ENhttps://mybatis.org/dtd/mybatis-3-config.dtd configuration ​settings!--日志实现--setting namelogImpl valueSTDOUT_LOGGING//settings ​environments defaultdevelopmentenvironment iddevelopmenttransactionManager typeJDBC/dataSource typePOOLEDproperty namedriver valuecom.mysql.jdbc.Driver/property nameurl valuejdbc:mysql://localhost:3306/mi?useSSLfalseamp;characterEncodingUTF-8/property nameusername valueroot/property namepassword valueAbc1234//dataSource/environment/environmentsmappers !--       mapper resourcecom/saas/dao/ProductsMapper.xml/--mapper classcom.saas.dao.IProductDaoAnnotation/ !--       package namecom.saas.dao/--/mappers /configuration 在mybatis的核心配置文件中mappers节点放入mapper子节点mapper标签中使用class属性来实现主责功能 或者在mappers节点中放入package子节点里面写name为包名那就意味着这个包下的所有dao类都可以被一次性注册到mybatis的核心工厂之上 package com.saas.dao; ​ import java.util.List; import com.saas.pojo.Product; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; ​ public interface IProductDaoAnnotation { ​Select(select * from products)ListProduct getAllProducts(); ​ //   Select(select * from products limit #{param1}, #{param2}) //   Select(select * from products limit #{arg0}, #{arg1})Select(select * from products limit #{si}, #{ps})ListProduct getProductsByPage(Param(si) int si, Param(ps) int ps); ​ ​Select(select * from products where cid #{cid})Product getProductById(int cid); ​Insert(insert into products(title,subtitle,wtype,oprice,tid,img,cdesc,nprice) values(#{title},#{subtitle},#{wtype},#{oprice},#{tid},#{img},#{cdesc},#{nprice}))int saveProduct(Product product); } 第三种调用方式与第二种类似 需要借助SqlSession对象的getMapper方法将接口的类对象传入后得到接口对象 一旦有了接口对象则通过接口对象的crud方法完成对应的curd功能 mybatis传参 无参SQL语句里面不写占位符 一参SQL语句里面#{}里面写任意合法的标识符 多参 对象传参 map传参 arg0 arg1 arg2 param1 param2 param3 Param“si”, Param(si) config配置 properties properties resourcedb.properties /properties settings settings setting namecacheEnabled valuetrue/ setting namelazyLoadingEnabled valuetrue/ setting nameaggressiveLazyLoading valuetrue/ setting namemultipleResultSetsEnabled valuetrue/ setting nameuseColumnLabel valuetrue/ setting nameuseGeneratedKeys valuefalse/ setting nameautoMappingBehavior valuePARTIAL/ setting nameautoMappingUnknownColumnBehavior valueWARNING/ setting namedefaultExecutorType valueSIMPLE/ setting namedefaultStatementTimeout value25/ setting namedefaultFetchSize value100/ setting namesafeRowBoundsEnabled valuefalse/ setting namesafeResultHandlerEnabled valuetrue/ setting namemapUnderscoreToCamelCase valuefalse/ setting namelocalCacheScope valueSESSION/ setting namejdbcTypeForNull valueOTHER/ setting namelazyLoadTriggerMethods valueequals,clone,hashCode,toString/ setting namedefaultScriptingLanguage valueorg.apache.ibatis.scripting.xmltags.XMLLanguageDriver/ setting namedefaultEnumTypeHandler valueorg.apache.ibatis.type.EnumTypeHandler/ setting namecallSettersOnNulls valuefalse/ setting namereturnInstanceForEmptyRow valuefalse/ setting namelogPrefix valueexampleLogPreFix_/ setting namelogImpl valueSLF4J | LOG4J | LOG4J2 | JDK_LOGGING | COMMONS_LOGGING | STDOUT_LOGGING | NO_LOGGING/ setting nameproxyFactory valueCGLIB | JAVASSIST/ setting namevfsImpl valueorg.mybatis.example.YourselfVfsImpl/ setting nameuseActualParamName valuetrue/ setting nameconfigurationFactory valueorg.mybatis.example.ConfigurationFactory/ /settings 类型别名 typeAliasestypeAlias typecom.saas.pojo.Product aliasProduct/package namecom.saas.pojo//typeAliases 环境配置 environments defaultdevelopmentenvironment iddevelopmenttransactionManager typeJDBC/dataSource typePOOLEDproperty namedriver value${driver}/property nameurl value${url}/property nameusername value${user}/property namepassword value${pass}//dataSource/environment /environments 其中datasource的type有三个值 unpooled不使用连接池 pooled使用连接池 jndi需要额外配置应用服务器 其中transactionManager的type值有两个: JDBC: jdbc自身的提交或者回滚来实现事务 MANAGED:由容器自动决定事务的提交或者回滚 映射器 mappers !-- mapper resourcecom/saas/dao/ProductsMapper.xml/--mapper classcom.saas.dao.IProductDaoAnnotation/ !-- package namecom.saas.dao/--/mappers 映射器的配置分为两大类 mapper子节点 resource配置xml文件的相对路径 url 配置xml文件的 绝对路径 class配置映射的文件类 package子节点该包下是所有类都会被自动映射 mapper映射 cache – 该命名空间的缓存配置。 cache-ref – 引用其它命名空间的缓存配置。 resultMap – 描述如何从数据库结果集中加载对象是最复杂也是最强大的元素。 parameterMap – 老式风格的参数映射。此元素已被废弃并可能在将来被移除请使用行内参数映射。文档中不会介绍此元素。 sql – 可被其它语句引用的可重用语句块。 insert – 映射插入语句。 update – 映射更新语句。 delete – 映射删除语句。 select – 映射查询语句。 sql idallProselect * from products/sqlselect idgetAllProducts resultTypeabcinclude refidallPro//selectselect idgetProductById resultTypeabcinclude refidallPro/where cid #{cid}/selectselect idgetProductsByPage resultTypeabcinclude refidallPro/limit #{si}, #{ps}/selectupdate idupdateProductupdate products set title #{title}, subtitle #{subtitle}, wtype #{wtype} , img #{img} ,cdesc #{cdesc} , oprice #{oprice}, nprice #{nprice}, tid #{tid} where cid #{cid}/update
http://www.w-s-a.com/news/916704/

相关文章:

  • 主机屋的免费空间怎么上传网站广告公司的经营范围有哪些
  • 门户网站建设公司案例门户建设是什么意思
  • 深圳seo专家东莞网站关键词优化排名
  • 套用别人产品图片做网站如何在阿里云自主建网站
  • 网站开发需要用哪些东西wordpress页面参数
  • 大连模板网站制作哪家好wordpress 安装不上
  • 宝塔搭建网站首页图片点击率如何提高
  • 长沙找人做网站wordpress如何安装模板
  • 比较好的国外网站建设公司wordpress短代码可视化
  • 做新的网站网站个性化
  • 吉安做网站的英文网站 字体大小
  • 外贸网站服务商wordpress主题handsome
  • 云主机多个网站如何优化网站图片
  • 松江移动网站建设成都app开发制作公司
  • 锦州做网站的公司百度seo搜索营销新视角
  • 做画册找什么网站海南建设工程股份有限公司网站
  • 网站机房建设有助于网站备案
  • 北辰苏州网站建设抖音代运营投诉平台
  • 安徽住房与城乡建设部网站如何新建站点
  • 企业网站开发的感想网站开发公司所需投入资源
  • 如何拿网站后台账号wordpress 电影下载站源码
  • 公司网站建设方案书安卓应用市场免费下载安装
  • phpmysql网站设计建设好一个网站需要
  • 自己做的网站能被别人看到吗idea怎么做网页
  • 燕莎网站建设互联网排名前十的公司2021
  • 微软云怎么做网站微商城和小程序区别
  • 哈尔滨建站的系统网站到首页排名
  • 运动网站开发的需求分析南通市住房和城乡建设局网站
  • 佘山做网站谷歌云做网站
  • 免费发布信息网站大全666做p2p网站费用