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

百度搜索网站包含的功能电子商务网站建设与规划

百度搜索网站包含的功能,电子商务网站建设与规划,网站做支付宝接口吗,引流软件下载站目录 十七、Spring6整合JUnit5 17.1Spring对JUnit4的支持 17.2Spring对JUnit5的支持 十八、Spring6集成MyBatis3.5 18.1实现步骤 18.2具体实现 18.3spring配置文件的import 十七、Spring6整合JUnit5 17.1Spring对JUnit4的支持 准备工作#xff1a; dependencies dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion6.0.3/version/dependency!--spring对junit4支持的依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactId!--这个版本spring6既支持JUnit4又支持JUnit5--version6.0.3/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.13.2/versionscopetest/scope/dependency /dependencies 声明Bean package com.hhb.bean; ​ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; ​ Component public class User {Value(张三)private String name; ​public User(String name) {this.name name;} ​public User() {} ​public String getName() {return name;} ​public void setName(String name) {this.name name;} ​Overridepublic String toString() {return User{ name name \ };} } spring.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd ​context:component-scan base-packagecom.hhb.bean/ /beans 单元测试 package com.hhb.test; ​ import com.hhb.bean.User; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ​ RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(classpath:spring.xml) public class SpringJUnit4Test {Autowiredprivate User user; ​Testpublic void testUser() {System.out.println(user.getName());} ​Testpublic void testUser1() {System.out.println(user.getName());} ​Testpublic void testUser2() {System.out.println(user.getName());} } Spring提供的方便主要是这几个注解 RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(classpath:spring.xml) 在单元测试类上使用这两个注解之后在单元测试类中的属性上可以使用Autowired比较方便。 17.2Spring对JUnit5的支持 引入JUnit5的依赖 dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion6.0.3/version/dependency!--spring对junit4支持的依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactId!--这个版本spring6既支持JUnit4又支持JUnit5--version6.0.3/version/dependency ​!--junit5依赖--dependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter/artifactIdversion5.9.0/versionscopetest/scope/dependency /dependencies 单元测试 package com.hhb.test; ​ import com.hhb.bean.User; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; ​ ExtendWith(SpringExtension.class) ContextConfiguration(classpath:spring.xml) public class SpringJUnit5Test { ​Autowiredprivate User user; ​Testpublic void testUser(){System.out.println(user.getName());} ​Testpublic void testUser2(){System.out.println(user.getName());} } 在JUnit5当中可以使用Spring提供的以下两个注解标注到单元测试类上这样类当中就可以使用Autowired注解了。 ExtendWith(SpringExtension.class) ContextConfiguration(classpath:spring.xml) 十八、Spring6集成MyBatis3.5 18.1实现步骤 第一步准备数据库表 使用t_act表账户表 第二步引入依赖 spring-context spring-jdbc mysql驱动 mybatis mybatis-springmybatis提供的与spring框架集成的依赖 德鲁伊连接池 junit 第三步基于三层架构实现提前准备好所有的包 com.hhb.bank.mapper com.hhb.bank.service com.hhb.bank.service.impl com.hhb.bank.pojo 第四步编写pojo Account属性私有化提供公开的setter、getter和toString。 第五步编写mapper接口 AccountMapper接口定义方法 第六步编写mapper配置文件 在配置文件中配置命名空间以及每一个方法对应的sql。 第七步编写service接口和service接口实现类 AccountService AccountServiceImpl 第八步编写jdbc.properties配置文件 数据库连接池相关信息 第九步编写mybatis-config.xml配置文件 该文件可以没有大部分的配置可以转移到spring配置文件中。 如果遇到mybatis相关的系统级配置还是需要这个文件。 第十步编写spring.xml配置文件 组件扫描 引入外部的属性文件 数据源 SqlSessionFactoryBean配置 注入mybatis核心配置文件路径 指定别名包 注入数据源 Mapper扫描配置器 指定扫描的包 事务管理器DataSourceTransactionManager 注入数据源 启用事务注解 注入事务管理器 第十一步编写测试程序并添加事务进行测试。 18.2具体实现 第一步准备数据库表 第二步引入依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersion ​groupIdorg.example/groupIdartifactIdspring016-sm/artifactIdversion1.0-SNAPSHOT/versionpackagingjar/packaging ​dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion6.0.3/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion6.0.3/version/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion8.0.30/version/dependencydependencygroupIdorg.mybatis/groupIdartifactIdmybatis/artifactIdversion3.5.10/version/dependencydependencygroupIdorg.mybatis/groupIdartifactIdmybatis-spring/artifactIdversion2.1.0/version/dependencydependencygroupIdcom.alibaba/groupIdartifactIddruid/artifactIdversion1.2.13/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.13.2/versionscopetest/scope/dependency/dependencies ​propertiesmaven.compiler.source20/maven.compiler.sourcemaven.compiler.target20/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/properties ​ /project 第三步基于三层架构实现所以提前创建好所有的包 第四步编写pojo package com.hhb.bank.pojo; ​ public class Account {private String actno;private Double balance; ​public Account() {} ​Overridepublic String toString() {return Account{ actno actno \ , balance balance };} ​public Account(String actno, Double balance) {this.actno actno;this.balance balance;} ​public String getActno() {return actno;} ​public void setActno(String actno) {this.actno actno;} ​public Double getBalance() {return balance;} ​public void setBalance(Double balance) {this.balance balance;} } 第五步编写mapper接口 package com.hhb.bank.mapper; ​ import com.hhb.bank.pojo.Account; ​ import java.util.List; ​ //这就是DAO public interface AccountMapper {//该接口的实现类不需要写是mybatis通过动态代理机制生成的实现类 ​//新增账户int insert(Account account); ​//根据账号删除账户int deleteByActno(String actno); ​//修改账户int update(Account account); ​//根据账号查询账户Account selectByActno(String actno); ​//查询所有账户ListAccount selectAll(); } 第六步编写mapper配置文件如果接⼝叫做AccountMapper配置⽂件必须是AccountMapper.xml ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.hhb.bank.mapper.AccountMapper ​insert idinsertinsert into t_actvalues (#{actno}, #{balance})/insert ​delete iddeleteByActnodeletefrom t_actwhere actno #{actno}/delete ​update idupdateupdate t_actset balance #{balance}where actno #{actno}/update ​select idselectByActno resultTypeAccountselect *from t_actwhere actno #{actno}/select ​select idselectAll resultTypeAccountselect *from t_act/select ​ /mapper 第七步编写service接口和service接口实现类注意编写的service实现类纳入IoC容器管理 package com.hhb.bank.service; ​ import com.hhb.bank.pojo.Account; ​ import java.util.List; ​ public interface AccountService {//开户int save(Account act); ​//销户int deleteByActno(String actno); ​//修改账户int modify(Account act); ​//查询账户Account getByActno(String actno); ​//获取所有账户ListAccount getAll(); ​//转账void transfer(String fromActno, String toActno, double money); ​ } package com.hhb.bank.service.impl; ​ import com.hhb.bank.mapper.AccountMapper; import com.hhb.bank.pojo.Account; import com.hhb.bank.service.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; ​ import java.util.List; ​ Transactional Service(accountService) public class AccountServiceImpl implements AccountService { ​Autowiredprivate AccountMapper accountMapper; ​Overridepublic int save(Account act) {return accountMapper.insert(act);} ​Overridepublic int deleteByActno(String actno) {return accountMapper.deleteByActno(actno);} ​Overridepublic int modify(Account account) {return accountMapper.update(account);} ​Overridepublic Account getByActno(String actno) {return accountMapper.selectByActno(actno);} ​Overridepublic ListAccount getAll() {return accountMapper.selectAll();} ​Overridepublic void transfer(String fromActno, String toActno, double money) {Account fromAct accountMapper.selectByActno(fromActno);if (fromAct.getBalance() money) {throw new RuntimeException(余额不足);}Account toAct accountMapper.selectByActno(toActno);fromAct.setBalance(fromAct.getBalance() - money);toAct.setBalance(toAct.getBalance() money);int count accountMapper.update(fromAct);/*String s null;s.toString();*/ ​count accountMapper.update(toAct);if (count ! 2) {throw new RuntimeException(转账失败);}} } 第八步编写jdbc.properties配置文件放在类的根路径下 jdbc.drivercom.mysql.cj.jdbc.Driver jdbc.urljdbc:mysql://localhost:3306/spring6 jdbc.usernameroot jdbc.password030522 第九步编写mybatis-config.xml配置文件放在类的根路径下 ?xml version1.0 encodingUTF-8 ? !DOCTYPE configurationPUBLIC -//mybatis.org//DTD Config 3.0//ENhttp://mybatis.org/dtd/mybatis-3-config.dtd configuration!--帮助我们打印mybatis的日志信息。sql语句等。--settingssetting namelogImpl valueSTDOUT_LOGGING//settings /configuration 第十步编写spring.xml配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/context xmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd ​!--组件扫描--!--context:component-scan base-packagecom.hhb.bank/--!--在spring的核心配置文件中引入子spring配置文件--import resourcecommon.xml/ ​!--引入外部的属性配置文件--context:property-placeholder locationjdbc.properties/ ​!--数据源--bean iddataSource classcom.alibaba.druid.pool.DruidDataSourceproperty namedriverClassName value${jdbc.driver}/property nameurl value${jdbc.url}/property nameusername value${jdbc.username}/property namepassword value${jdbc.password}//bean ​!--配置SqlSessionFactoryBean--bean classorg.mybatis.spring.SqlSessionFactoryBean!--注入数据源--property namedataSource refdataSource/!--指定mybatis核心配置文件--property nameconfigLocation valuemybatis-config.xml/!--指定别名--property nametypeAliasesPackage valuecom.hhb.bank.pojo//bean ​!--Mapper扫描配置器主要扫描Mapper接口生成代理类--bean classorg.mybatis.spring.mapper.MapperScannerConfigurerproperty namebasePackage valuecom.hhb.bank.mapper//bean ​!--事务管理器--bean idtxManager classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdataSource//bean ​!--启用事务注解--tx:annotation-driven transaction-managertxManager/ /beans 第十一步编写测试程序并添加事务进行测试 package com.hhb.bank.test; ​ import com.hhb.bank.service.AccountService; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; ​ public class BankSMTest {Testpublic void testSM(){ApplicationContext applicationContext new ClassPathXmlApplicationContext(spring.xml);AccountService accountService applicationContext.getBean(accountService, AccountService.class);try {accountService.transfer(act001, act002, 10000);System.out.println(转账成功);} catch (Exception e){e.printStackTrace();}} } 18.3spring配置文件的import spring配置文件有多个并且可以在spring的核心配置文件中使用import进行引入我们可以将组件扫描单独定义到一个配置文件中如下 common.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd ​!--组件扫描--context:component-scan base-packagecom.hhb.bank/ /beans 在核心配置文件中引入 import resourcecommon.xml/ 注意在实际开发中service单独配置到一个文件中dao单独配置到一个文件中然后在核心配置文件中引入养成好习惯。
http://www.zqtcl.cn/news/931439/

相关文章:

  • 文化馆网站建设情况网站建设建站公司
  • 自己怎么做dj 视频网站网站推广 济南
  • 2014网站怎么备案怎样建置换平台网站
  • 惠州网站建设信息嘉兴做网站软件
  • 如何做发表文章的网站淮安市建设工程质量监督站网站
  • 做洁净的网站太原便宜做网站的公司
  • 网站设计评级检索标准的网站
  • 做个网站每年都要交域名费吗html静态网页首页模板
  • 网站资源整合与建设wordpress固定链接设置后404
  • 网站历史快照seo推广方法
  • 做淘宝客的的网站有什么要求北京专业网站制作公司
  • 建设网站 知乎个人可以开发app软件吗
  • 网站如何后台管理北京正规网站建设有几种
  • 临沂网站排名高质量的中山网站建设
  • 响应式网站定制开发网络教育全程托管
  • 做网站中的剪辑图片龙岗网站
  • 建设购物网站的意义免费做外贸的网站平台
  • 长沙做电商网站设计重庆观音桥旅游攻略
  • 网站建设的目标与期望动漫设计与制作工资多少
  • 做网站找网站设计公司 长沙
  • 网站维护内容网站代码下载
  • 西安建设主管部门官方网站wordpress返回件
  • 建立免费空间网站南宁seo推广外包
  • 网站初期如何推广用秀米制作h5详细步骤
  • 做网站需要执照嘛开发 网站 团队
  • 怎么提交网站关键词包头人脸检测系统
  • 哪个网站开发是按月付费的婚纱摄影建设网站的目的
  • 站长之家app简单网站制作步骤
  • 网站开发与桌面应用开发wordpress if include
  • 网站怎么做预约小程序江苏省工程建设招标网站