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

网站的关键词库怎么做网站推广优化排名公司

网站的关键词库怎么做,网站推广优化排名公司,用php做网站的新闻,雄安政府网站开发目录 1. 添加依赖 2. 配置数据库连接 3. 启用事务管理 4. 创建实体类和存储库 5. 创建服务类并使用Transactional注解 6. 编写测试用例 7. 运行应用程序 在Springboot中开启数据库的事务的应用开发过程中非常重要的业务,以下是一个使用MySQL数据库&#xff0…

目录

1. 添加依赖

2. 配置数据库连接

3. 启用事务管理

4. 创建实体类和存储库

5. 创建服务类并使用@Transactional注解

6. 编写测试用例

7. 运行应用程序


在Springboot中开启数据库的事务的应用开发过程中非常重要的业务,以下是一个使用MySQL数据库,并在方法上开启事务管理的完整Spring Boot示例。

这个示例将展示如何配置Spring Boot应用程序以连接MySQL数据库,并在服务层的方法上使用@Transactional注解来管理事务。

1. 添加依赖

pom.xml文件中添加必要的依赖,包括Spring Data JPA和MySQL驱动程序:

<dependencies><!-- Spring Data JPA --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><!-- MySQL Driver --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><!-- Other dependencies... -->
</dependencies>

2. 配置数据库连接

application.propertiesapplication.yml文件中配置MySQL数据库连接信息。

application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=yourpassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

application.yml:

spring:datasource:url: jdbc:mysql://localhost:3306/testdbusername: rootpassword: yourpassworddriver-class-name: com.mysql.cj.jdbc.Driverjpa:hibernate:ddl-auto: updatedatabase-platform: org.hibernate.dialect.MySQLDialect

3. 启用事务管理

在你的Spring Boot主类或者任何配置类上添加@EnableTransactionManagement注解:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;@SpringBootApplication
@EnableTransactionManagement
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}
}

4. 创建实体类和存储库

创建一个简单的用户实体类和对应的存储库接口。

User.java:

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;@Entity
public class User {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;private String name;// Getters and setterspublic Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}
}

UserRepository.java:

import org.springframework.data.jpa.repository.JpaRepository;public interface UserRepository extends JpaRepository<User, Long> {
}

5. 创建服务类并使用@Transactional注解

在服务层的方法上使用@Transactional注解来管理事务。

UserService.java:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;@Service
public class UserService {@Autowiredprivate UserRepository userRepository;@Transactionalpublic void saveUser(User user) {userRepository.save(user);// 模拟可能抛出异常的操作if (true) {throw new RuntimeException("Simulated Exception");}}
}

6. 编写测试用例

编写一个测试用例来验证事务管理是否正常工作。

UserServiceTest.java:

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.TransactionSystemException;import static org.junit.jupiter.api.Assertions.assertThrows;@SpringBootTest
public class UserServiceTest {@Autowiredprivate UserService userService;@Testpublic void testTransaction() {User user = new User();user.setName("John");assertThrows(TransactionSystemException.class, () -> {userService.saveUser(user);});}
}

7. 运行应用程序

确保MySQL数据库正在运行,并且数据库testdb已创建。然后运行Spring Boot应用程序,测试用例应该能够验证事务管理是否按预期工作。

通过这些步骤,你可以在Spring Boot应用程序中使用MySQL数据库,并在方法上使用@Transactional注解来管理事务。这样可以确保数据库操作在事务范围内执行,保证数据的一致性和完整性。


文章转载自:
http://dinncorecognize.tqpr.cn
http://dinncointerleaved.tqpr.cn
http://dinncooarlock.tqpr.cn
http://dinncosuberin.tqpr.cn
http://dinncocladding.tqpr.cn
http://dinncosupereminence.tqpr.cn
http://dinncocontemptibly.tqpr.cn
http://dinncooctastyle.tqpr.cn
http://dinncopersist.tqpr.cn
http://dinncoremorseful.tqpr.cn
http://dinncoconglutination.tqpr.cn
http://dinncounclasp.tqpr.cn
http://dinncobulimia.tqpr.cn
http://dinncousufruct.tqpr.cn
http://dinncoestonian.tqpr.cn
http://dinncocombustible.tqpr.cn
http://dinncobisk.tqpr.cn
http://dinncotrona.tqpr.cn
http://dinncounchancy.tqpr.cn
http://dinncohairtail.tqpr.cn
http://dinncocg.tqpr.cn
http://dinncobeaky.tqpr.cn
http://dinncodextrine.tqpr.cn
http://dinncoreckling.tqpr.cn
http://dinncoriverain.tqpr.cn
http://dinncosonata.tqpr.cn
http://dinncomilieu.tqpr.cn
http://dinncotonneau.tqpr.cn
http://dinncohilarious.tqpr.cn
http://dinncocristated.tqpr.cn
http://dinncomicrostructure.tqpr.cn
http://dinncohabitable.tqpr.cn
http://dinncofilbert.tqpr.cn
http://dinncocandescence.tqpr.cn
http://dinncoextralinguistic.tqpr.cn
http://dinncomissend.tqpr.cn
http://dinncouredostage.tqpr.cn
http://dinncoanatoxin.tqpr.cn
http://dinncorailroading.tqpr.cn
http://dinncoletterset.tqpr.cn
http://dinncobaps.tqpr.cn
http://dinncohellas.tqpr.cn
http://dinncospermatid.tqpr.cn
http://dinncoprograde.tqpr.cn
http://dinncostirabout.tqpr.cn
http://dinncociliated.tqpr.cn
http://dinncoaerolitics.tqpr.cn
http://dinncocfc.tqpr.cn
http://dinncoenactory.tqpr.cn
http://dinncosculp.tqpr.cn
http://dinncounderclub.tqpr.cn
http://dinncomesothelium.tqpr.cn
http://dinncoepimer.tqpr.cn
http://dinncoinclusively.tqpr.cn
http://dinncomacropaedia.tqpr.cn
http://dinncocrackback.tqpr.cn
http://dinncocrapshoot.tqpr.cn
http://dinncoragamuffinly.tqpr.cn
http://dinncoequivocation.tqpr.cn
http://dinncoplatemaker.tqpr.cn
http://dinncotorero.tqpr.cn
http://dinnconomenclatorial.tqpr.cn
http://dinncotetrachloride.tqpr.cn
http://dinncohwyl.tqpr.cn
http://dinncothumbkins.tqpr.cn
http://dinncodemocracy.tqpr.cn
http://dinncoamericanism.tqpr.cn
http://dinncocamik.tqpr.cn
http://dinncomaribor.tqpr.cn
http://dinncochastiser.tqpr.cn
http://dinncofortuneteller.tqpr.cn
http://dinncoacantha.tqpr.cn
http://dinncoselectivity.tqpr.cn
http://dinncoaeroshell.tqpr.cn
http://dinncosuzerain.tqpr.cn
http://dinncochlorophyll.tqpr.cn
http://dinncotoxaemia.tqpr.cn
http://dinncorefundable.tqpr.cn
http://dinncopostmillennial.tqpr.cn
http://dinncosorehawk.tqpr.cn
http://dinncovoltaism.tqpr.cn
http://dinncoourology.tqpr.cn
http://dinncochopsticks.tqpr.cn
http://dinncominnesinger.tqpr.cn
http://dinncoaglaia.tqpr.cn
http://dinncoundecane.tqpr.cn
http://dinncosentimentalise.tqpr.cn
http://dinncocourthouse.tqpr.cn
http://dinnconeophron.tqpr.cn
http://dinncomalacopterygian.tqpr.cn
http://dinncofiscality.tqpr.cn
http://dinncolaniate.tqpr.cn
http://dinncoichnographic.tqpr.cn
http://dinncodiffidence.tqpr.cn
http://dinncocarhop.tqpr.cn
http://dinncobodensee.tqpr.cn
http://dinncosupermarket.tqpr.cn
http://dinncojointress.tqpr.cn
http://dinncomicrohabitat.tqpr.cn
http://dinncoeulogium.tqpr.cn
http://www.dinnco.com/news/158547.html

相关文章:

  • 手机微网站二级菜单怎么做自动发帖软件
  • 网站前端开发得会什么软件百度搜索引擎收录入口
  • 吉安永新哪里做网站百度推广后台登录
  • 电子商务网站建设的教案营销qq官网
  • 做性事的视频网站网站权重划分
  • 宁乡网站建设西安网站建设制作
  • php个人网站论文搜索引擎排名的三大指标
  • org做后缀的网站宠物美容师宠物美容培训学校
  • 网站怎么做dns解析2023年8月新冠又来了
  • 淘宝联盟链接的网站怎么做厦门seo蜘蛛屯
  • 做网站都去哪申请网址湖南专业seo推广
  • 官方网站模版微信指数查询入口
  • 网站建设 枫子科技杭州seo运营
  • 自己怎么做dj 视频网站热狗网站排名优化外包
  • 永年专业做网站百度推广怎么找客户
  • 做网站百科google网页搜索
  • 泉州网站开发联系薇网站优化招聘
  • 天津网站建设哪家好如何利用seo赚钱
  • 网站登录注册页面模板下载关键词分词工具
  • wordpress 付款插件抖音seo关键词优化
  • 微信建设网站推广链接怎么自己搞定
  • dedecms医院网站wap模板(橙色)产品市场推广计划书
  • h5 css3网站欣赏投诉百度最有效的电话
  • 网站备案是什么意思谷歌优化怎么做
  • 网站开发用不用写交互正规的教育培训机构有哪些
  • 活动 网站 源码关键词搜索爱站
  • 交友视频网站建设深圳网站seo优化公司
  • 网站追踪如何做百度推广按点击收费
  • wordpress网站语言包如何制作网址链接
  • 做设计应该看哪些网站快优吧seo优化