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

dede wap网站模板网站显示图片标记

dede wap网站模板,网站显示图片标记,成品网站1688入口,产品关键词文章目录 Spring JdbcTemplateJdbcTemplate概述JdbcTemplate开发步骤Spring产生JdbcTemplate对象 Spring JdbcTemplate JdbcTemplate概述 它是spring框架中提供的一个对象#xff0c;是对原始繁琐的JdbcAPI对象的简单封装。spring框架为我们提供了很多的操作模板类。例如是对原始繁琐的JdbcAPI对象的简单封装。spring框架为我们提供了很多的操作模板类。例如操作关系型数据的JdbcTemplate和HibernateTemplate操作nosql数据库的RedisTemplate操作消息队列的JmsTemplate等等。 JdbcTemplate开发步骤 ① 导入spring-jdbc和spring-tx坐标 ② 创建数据库表和实体 ③ 创建JdbcTemplate对象 ④ 执行数据库操作 ① 导入spring-jdbc和spring-tx坐标 dependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion5.2.8.RELEASE/version/dependency!--导入spring的tx坐标--dependencygroupIdorg.springframework/groupIdartifactIdspring-tx/artifactIdversion5.2.8.RELEASE/version/dependency②创建accout表和Accout实体 public class Account {private String name;private double money;//省略get和set方法 }③创建JdbcTemplate对象 ④执行数据库操作 //1、创建数据源对象 ComboPooledDataSource dataSource new ComboPooledDataSource();dataSource.setDriverClass(com.mysql.jdbc.Driver);dataSource.setJdbcUrl(jdbc:mysql://localhost:3306/test);dataSource.setUser(root);dataSource.setPassword(root);//2、创建JdbcTemplate对象 JdbcTemplate jdbcTemplate new JdbcTemplate();//3、设置数据源给JdbcTemplatejdbcTemplate.setDataSource(dataSource);//4、执行操作 jdbcTemplate.update(insert into account values(?,?),tom,5000);Spring产生JdbcTemplate对象 我们可以将JdbcTemplate的创建权交给Spring将数据源DataSource的创建权也交给Spring在Spring容器内部将数据源DataSource注入到JdbcTemplate模版对象中配置如下 !--数据源DataSource--bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSourceproperty namedriverClass valuecom.mysql.jdbc.Driver/propertyproperty namejdbcUrl valuejdbc:mysql:///test/propertyproperty nameuser valueroot/propertyproperty namepassword valueroot/property/bean!--JdbcTemplate--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdataSource/property/bean从容器中获得JdbcTemplate进行添加操作 Testpublic void testSpringJdbcTemplate() throws PropertyVetoException{ApplicationContext applicationContext new ClassPathXmlApplicationContext(applicationContext.xml);JdbcTemplate jdbcTemplate applicationContext.getBean(JdbcTemplate.class);jdbcTemplate.update(insert into account values(?,?),lucy,5000);}修改操作 RunWith(SpringJUnit4ClassRunner.class)ContextConfiguration(classpath:applicationContext.xml)public class JdbcTemplateCRUDTest {Autowiredprivate JdbcTemplate jdbcTemplate;Test//测试修改操作 public void testUpdate(){jdbcTemplate.update(update account set money? where name?,1000,tom);}}删除和查询全部操作 Testpublic void testDelete(){jdbcTemplate.update(delete from account where name?,tom);}Testpublic void testQueryAll(){ListAccount accounts jdbcTemplate.query(select * from account, new BeanPropertyRowMapperAccount(Account.class));for (Account account : accounts) {System.out.println(account.getName());}}查询单个数据操作操作 Test//测试查询单个对象操作 public void testQueryOne(){Account account jdbcTemplate.queryForObject(select * from account where name?, new BeanPropertyRowMapperAccount(Account.class), tom);System.out.println(account.getName());}Test//测试查询单个简单数据操作(聚合查询)public void testQueryCount(){Long aLong jdbcTemplate.queryForObject(select count(*) from account, Long.class);System.out.println(aLong);}
http://www.zqtcl.cn/news/140750/

相关文章:

  • discuz仿搜索网站做网站开发用哪种语言好
  • 企业网站服务网络设备维护是做什么的
  • 罗湖网站公司网站服务器建设合同
  • 公司网站设计注意什么免费名字设计成图案
  • python3 网站建设济南网站建设(选 聚搜网络)
  • 建网站在哪里做广告上海 网站撤销备案
  • 个人可以备案几个网站做网站和网站页面设计
  • 拉丝机东莞网站建设下载安装百度一下
  • 河北建设厅官方网站山西手动网站建设推广
  • 连云港网站建设开发网络营销顾问服务
  • 怎么做网站免有什么网站可以免费建站
  • 安全的营销型网站建设深圳网站建设哪家
  • wordpress能开发商城网站吗seo软件
  • 广东网站建设制作价格低网页升级访问中每天正常更新中
  • 北京市门头沟有没有做网站的小水库运行管理培训教材久久建筑网
  • 免费手机网站app软文推广发稿
  • 安徽网站制作公司建设银行校招网站入口
  • 专业的网站公司到哪里找会员网站模板
  • 山西城乡和建设厅网站首页应用公园下载
  • 自动优化网站建设电话wordpress 后端
  • 淘客网站怎么做啊做网站是什么工作
  • 新媒体 网站建设 管理规范专门卖医疗器械的网站
  • 高水平建设专业网站微商城网站建设平台合同
  • 策划的网站在哪个网站做一照一码
  • wordpress页面如何排序网站优化推广软件
  • 网站描述和关键词怎么写智慧团建网站pc端
  • 苏州营销型网站建设推广医院做网站备案需要哪些资料
  • 怎么看是哪家做的网站呼市浩特网站建设
  • 如何建设淘宝客网站全网营销包括什么
  • 网站建设服务市场广州市几个区