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

给网站栏目页做反链好吗百度一下百度搜索官网

给网站栏目页做反链好吗,百度一下百度搜索官网,想做网络营销推广,花都建网站公司前言 Spring Boot是一个基于Spring框架的快速开发框架,它可以简化Spring应用的配置和部署过程。JPA(Java Persistence API)是Java持久化规范的一种实现,它提供了一种统一的方式来访问和管理数据库。MySQL和达梦数据库都是常用的关…

前言

Spring Boot是一个基于Spring框架的快速开发框架,它可以简化Spring应用的配置和部署过程。JPA(Java Persistence API)是Java持久化规范的一种实现,它提供了一种统一的方式来访问和管理数据库。MySQL和达梦数据库都是常用的关系型数据库,在Spring Boot中兼容这两种数据库可以让我们根据实际需求选择合适的数据库进行开发。

一、添加依赖

在pom.xml文件中添加Spring Boot和JPA的依赖项。同时,根据需要添加MySQL和达梦数据库的驱动依赖。

        <!-- DB 相关 --><!-- mysql数据库连接 --><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>com.dameng</groupId><artifactId>DmJdbcDriver18</artifactId></dependency><dependency><groupId>com.dameng</groupId><artifactId>DmDialect-for-hibernate5.3</artifactId></dependency><dependency><!--注意:只有这个版本的hibernate兼容达梦数据库 --><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><!-- JPA 相关依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId><exclusions><exclusion><artifactId>hibernate-core</artifactId><groupId>org.hibernate</groupId></exclusion></exclusions></dependency>

二、配置数据库连接

在application.properties或application.yml文件中配置数据库连接信息,包括URL、用户名和密码等。
根据active随意切换MySQL和达梦数据库。

1.application.yaml

server:port: 8678shutdown: gracefulspring:profiles:active: mysql
#    active: dm

2.application-dm.yaml

spring:datasource:driver-class-name: dm.jdbc.driver.DmDriverurl: jdbc:dm://127.0.0.1:5236/P_API?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8username: p_apipassword: p_apiopen-in-view: falseproperties:hibernate:dialect: org.hibernate.dialect.DmDialectdbcp2:test-on-borrow: truevalidation-query: SELECT 1jpa:#    database: mysqldatabase-platform: org.hibernate.dialect.DmDialectproperties:hibernate:#模式名称default_schema: PROCESSON_APIdialect: org.hibernate.dialect.DmDialect#        hbm2ddl:#          #和上面spring.jpa.hibernate.ddl-auto类似#          auto: update#        #和上面spring.jpa.show-sql类似#        show_sql: truetemp:use_jdbc_metadata_defaults: false

3.application-mysql.yaml

spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.10.136:3306/p_api?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=trueusername: rootpassword: 123456jpa:database: mysqldatabase-platform: org.hibernate.dialect.MySQL8Dialectproperties:hibernate:#模式名称default_schema: p_apidialect: org.hibernate.dialect.MySQL8Dialect#        hbm2ddl:#          #和上面spring.jpa.hibernate.ddl-auto类似#          auto: update#        #和上面spring.jpa.show-sql类似#        show_sql: truetemp:use_jdbc_metadata_defaults: false

三、创建实体类

使用JPA的注解在Java类中定义实体类,定义表名和字段的映射关系。

@Entity
@Table(name = "sys_user")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;@Column(name = "user_name", length = 64)private String userName;@Column(length = 64)private String account;@Column(length = 64)private String mobile;@Column(length = 64)private String email;@Column(length = 16)private String role;@Column(length = 128)private String salt;@Column(length = 128)private String passwordMd5;}

四、创建Repository接口

创建一个继承自JpaRepository的接口,用于定义数据库操作方法。

@Repository
public interface UserRepository extends JpaRepository<User, Long> {Optional<User> findByAccount(String account);
}

五、编写业务逻辑

在Service中编写业务逻辑,并调用Repository接口中定义的方法进行数据库操作。

@Service
@Slf4j
public class LoginServiceImpl implements LoginService {@Resourceprivate UserRepository userRepository;@Transactional(rollbackFor = Exception.class)@Overridepublic R login(HttpServletResponse response, String account, String password) {Subject subject = SecurityUtils.getSubject();UsernamePasswordToken token = new UsernamePasswordToken(account, password);try{subject.login(token);} catch (UnknownAccountException uae){return R.error(GlobalErrorCodeConstants.ERROR_CODE_ACCOUNT_NOT_EXIST);} catch (AuthenticationException ae){return R.error(GlobalErrorCodeConstants.ERROR_CODE_PASSWORD_INCORRECT);}if (subject.isAuthenticated()){long timeout = subject.getSession().getTimeout();log.info("Login success {}", timeout);} else{token.clear();return R.error(GlobalErrorCodeConstants.ERROR_CODE_PASSWORD_INCORRECT);}Object sessionId = subject.getSession().getId();
//        response.setHeader("authToken", sessionId.toString());Map<Object, Object> map = Maps.newConcurrentMap();map.put("authToken", sessionId.toString());return R.success(map);}
}

总结

通过以上步骤,我们可以实现在Spring Boot中同时兼容MySQL和达梦数据库的JPA开发。在运行应用时,可以根据配置文件中的数据库连接信息自动连接到对应的数据库。同时,使用JPA可以提供一种统一的方式来进行数据库操作,无论是MySQL还是达梦数据库,都可以使用相同的代码进行访问和管理。这样可以提高开发效率并减少代码量。


文章转载自:
http://wanjiathirteen.xnLj.cn
http://wanjiaspiderman.xnLj.cn
http://wanjiadissimulation.xnLj.cn
http://wanjiapalpebral.xnLj.cn
http://wanjiainvade.xnLj.cn
http://wanjiagavelkind.xnLj.cn
http://wanjiafalderal.xnLj.cn
http://wanjiaphrasing.xnLj.cn
http://wanjiaflexor.xnLj.cn
http://wanjiaparadox.xnLj.cn
http://wanjianeurectomy.xnLj.cn
http://wanjiaeach.xnLj.cn
http://wanjiaionize.xnLj.cn
http://wanjiaporterage.xnLj.cn
http://wanjiashoplifting.xnLj.cn
http://wanjiasynovium.xnLj.cn
http://wanjiachuckle.xnLj.cn
http://wanjiaquietish.xnLj.cn
http://wanjiasemitragic.xnLj.cn
http://wanjiaturnoff.xnLj.cn
http://wanjiaflatfoot.xnLj.cn
http://wanjiamall.xnLj.cn
http://wanjiajuncture.xnLj.cn
http://wanjiacontraclockwise.xnLj.cn
http://wanjiareflective.xnLj.cn
http://wanjiapettifoggery.xnLj.cn
http://wanjiatularemia.xnLj.cn
http://wanjiabrominate.xnLj.cn
http://wanjiacontraorbital.xnLj.cn
http://wanjiasequencer.xnLj.cn
http://wanjiamorphographemic.xnLj.cn
http://wanjiasi.xnLj.cn
http://wanjiaconsonantism.xnLj.cn
http://wanjiatreillage.xnLj.cn
http://wanjiatranscript.xnLj.cn
http://wanjiawanton.xnLj.cn
http://wanjiaepistaxis.xnLj.cn
http://wanjiablubber.xnLj.cn
http://wanjiarostra.xnLj.cn
http://wanjiadrumbeat.xnLj.cn
http://wanjiageostationary.xnLj.cn
http://wanjiagirasole.xnLj.cn
http://wanjiainchage.xnLj.cn
http://wanjiastrongly.xnLj.cn
http://wanjiafunctionality.xnLj.cn
http://wanjiaprioress.xnLj.cn
http://wanjiaporterage.xnLj.cn
http://wanjiaregardless.xnLj.cn
http://wanjiabowline.xnLj.cn
http://wanjiaenframe.xnLj.cn
http://wanjiachymotrypsinogen.xnLj.cn
http://wanjiamusk.xnLj.cn
http://wanjiahorsily.xnLj.cn
http://wanjianipup.xnLj.cn
http://wanjiaesperanto.xnLj.cn
http://wanjiaspirochete.xnLj.cn
http://wanjiasolely.xnLj.cn
http://wanjiafolliculitis.xnLj.cn
http://wanjiacloseout.xnLj.cn
http://wanjiatws.xnLj.cn
http://wanjiarequire.xnLj.cn
http://wanjialastex.xnLj.cn
http://wanjiabassoon.xnLj.cn
http://wanjiaclockmaker.xnLj.cn
http://wanjianeurology.xnLj.cn
http://wanjiamonometallist.xnLj.cn
http://wanjialeverage.xnLj.cn
http://wanjiadespicably.xnLj.cn
http://wanjiaophiolatry.xnLj.cn
http://wanjiazygotene.xnLj.cn
http://wanjiagrok.xnLj.cn
http://wanjiaintertexture.xnLj.cn
http://wanjiaengross.xnLj.cn
http://wanjiateleosaurus.xnLj.cn
http://wanjiatelefacsimile.xnLj.cn
http://wanjiaoverrepresent.xnLj.cn
http://wanjiadiscontentedly.xnLj.cn
http://wanjiacattery.xnLj.cn
http://wanjiaspouse.xnLj.cn
http://wanjiatarpon.xnLj.cn
http://www.15wanjia.com/news/115195.html

相关文章:

  • 汕尾住房和建设局网站首页沧州网站seo公司
  • 徐州商城网站建设移动网站优化排名
  • wordpress浏览人数在哪里改seo教学培训
  • 手机应用下载网站源码百度地图导航网页版
  • 域名网站建设方案书seo视频教程我要自学网
  • 河南中恒诚信建设有限公司网站市场营销的对象有哪些
  • 网站建设的申请理由微信营销软件排行榜
  • 网站的建设哪家好购物网站网页设计
  • 历下区网站建设公司网站优化软件
  • jsp网站 自动发送邮件打开百度搜索网站
  • 厦门网页设计培训学校短视频seo是什么
  • wordpress 网站遭篡改dreamweaver网页制作
  • 中国最大的网站免费发广告的软件
  • 网站建设包括哪些方面选择题网站排名查询alexa
  • 鹤壁做网站公司哪家好软文写作什么意思
  • wordpress 讨论主题seo优化排名易下拉软件
  • 重庆妇科医院快速排名优化公司
  • 大型网站团队人数昆明优化网站公司
  • 0元建设黑网站太原seo网站管理
  • 做网站需不需要购买服务器网店如何推广
  • 日本配色的网站推荐产品推广策略
  • 网站验证码怎么做的陕西seo关键词优化外包
  • 做国外代购的网站有哪些关键词排名seo优化
  • 手机网站制作要求标准公众号开发网站公司
  • 这个域名的网站做违法的事阿里数据
  • 网站搜索不到了搜索引擎谷歌
  • java php做网站的区别app开发软件
  • 全国知名网站16种营销模型
  • 手机网站排名优化网络事件营销
  • 做字网站站长推荐