org.springframework.boot
spring-boot-starter-parent
1.2.5.RELEASE
–>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<openjpa.version>3.1.0</openjpa.version>
<spring.boot.version>1.2.5.RELEASE</spring.boot.version>
<spring.version>4.2.1.RELEASE</spring.version>
org.springframework.boot
spring-boot-starter-data-jpa
${spring.boot.version}
hibernate-entitymanager
org.hibernate
org.springframework.boot
spring-boot-starter-logging
${spring.boot.version}
org.apache.openjpa
openjpa-all
${openjpa.version}
system
${project.basedir}/libs/openjpa-all-3.1.0.jar
com.gbase
gbasedbtjdbc
1.0
system
${project.basedir}/libs/gbasedbtjdbc.jar
org.springframework.boot
spring-boot-starter-test
${spring.boot.version}
test
org.springframework.boot
spring-boot-starter-web
${spring.boot.version}
org.apache.maven.plugins
maven-compiler-plugin
3.1
${java.version}${java.version}
${project.build.sourceEncoding}
-Xlint:all
true
org.springframework.boot
spring-boot-maven-plugin
${spring.boot.version}
org.springframework
springloaded
1.2.4.RELEASE
org.springframework
spring-instrument
${spring.version}
s e t t i n g s . l o c a l R e p o s i t o r y / o r g / s p r i n g f r a m e w o r k / s p r i n g − i n s t r u m e n t / {settings.localRepository}/org/springframework/spring-instrument/ settings.localRepository/org/springframework/spring−instrument/{spring.version}/spring-instrument-${spring.version}.jar
s e t t i n g s . l o c a l R e p o s i t o r y / o r g / a p a c h e / o p e n j p a / o p e n j p a / {settings.localRepository}/org/apache/openjpa/openjpa/ settings.localRepository/org/apache/openjpa/openjpa/{openjpa.version}/openjpa-${openjpa.version}.jar
org.apache.openjpa
openjpa-maven-plugin
${openjpa.version}
**/entity/*.class
true
true
src/main/resources/schema.sql
src/main/resources/META-INF/persistence.xml
enhancer
process-classes
enhance
jpa配置,创建persistence.xml
放在 src\main\resources\META-INF
下
<persistence version=“1.0”
xmlns=“http://java.sun.com/xml/ns/persistence” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
org.apache.openjpa.persistence.PersistenceProviderImpl
wang.datahub.example.entity.Userinfo
<property name=“openjpa.ConnectionURL”
value=“jdbc:gbasedbt-sqli://172.24.110.229:90881/t1:GBASEDBTSERVER=ol_gbasedbt1210_1;NEWCODESET=UTF8,zh_cn.UTF8,57372;DATABASE=t1;DB_LOCALE=en_US.819;”/>
<property name=“openjpa.ConnectionDriverName”
value=“com.gbasedbt.jdbc.Driver”/>
<property name=“openjpa.ConnectionUserName”
value=“gbasedbt”/>
<property name=“openjpa.ConnectionPassword”
value=“dafei1288”/>
系统配置application.yml
server:
port: 8088
context-path: /
#spring-jpa-data数据库配置信息 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
spring:
jpa:
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: create-drop
datasource:
driver-class-name: com.gbasedbt.jdbc.Driver
url: jdbc:gbasedbt-sqli://172.24.110.229:9088/t1:GBASEDBTSERVER=ol_gbasedbt1210_1;NEWCODESET=UTF8,zh_cn.UTF8,57372;DATABASE=t1;DB_LOCALE=en_US.819;
username: gbasedbt
password: dafei1288
创建实体类:
package wang.datahub.example.entity;
import javax.persistence.*;
@Entity
@Table
public class Userinfo {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column
private String username;
@Column
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return “Userinfo{” +
“id='” + id + ‘’’ +
“, username='” + username + ‘’’ +
“, age=” + age +
‘}’;
}
}
创建UserinfoRepository
用于完成持久化操作
package wang.datahub.example.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import wang.datahub.example.entity.Userinfo;
@Repository
public interface UserinfoRepository extends JpaRepository<Userinfo, String> {
}
创建UserinfoService
接口,以及其实现类,这里仅以增加记录和查询记录为例:
package wang.datahub.example.service;
import wang.datahub.example.entity.Userinfo;
import java.util.List;
public interface UserinfoService {
List getAll();
Userinfo saveOne(Userinfo userinfo);
}
UserinfoServiceImpl实现
package wang.datahub.example.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wang.datahub.example.entity.Userinfo;
import wang.datahub.example.repository.UserinfoRepository;
import wang.datahub.example.service.UserinfoService;
import java.util.List;
@Service
public class UserinfoServiceImpl implements UserinfoService {
@Autowired
private UserinfoRepository userinfoRepository;
@Override
public List getAll(){
return userinfoRepository.findAll();
}
@Override
public Userinfo saveOne(Userinfo userinfo){
System.out.println(userinfo);
return userinfoRepository.saveAndFlush(userinfo);
}
}
创建Rest接口 UserinfoController
package wang.datahub.example.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import wang.datahub.example.entity.Userinfo;
import wang.datahub.example.service.UserinfoService;
import java.util.List;
@RestController
public class UserinfoController {
@Autowired
private UserinfoService userinfoService;
@RequestMapping(value = “/userinfo”, method = RequestMethod.GET)
public List getAll(){
return userinfoService.getAll();
}
@RequestMapping(value=“/userinfo”,produces = “application/json;charset=UTF-8”, method = RequestMethod.POST)
public Userinfo save(@RequestBody Userinfo userinfo){
return userinfoService.saveOne(userinfo);
}
}
创建启动类 App
package wang.datahub.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter;
import org.springframework.transaction.jta.JtaTransactionManager;
import javax.persistence.spi.PersistenceProvider;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)

惊喜
最后还准备了一套上面资料对应的面试题(有答案哦)和面试时的高频面试算法题(如果面试准备时间不够,那么集中把这些算法题做完即可,命中率高达85%+)
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
不知道该从何学起的朋友,同时减轻大家的负担。**[外链图片转存中…(img-rT6W3Pqk-1713399591000)]
[外链图片转存中…(img-hD0IavBa-1713399591001)]
[外链图片转存中…(img-DhKFBxWW-1713399591001)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)

惊喜
最后还准备了一套上面资料对应的面试题(有答案哦)和面试时的高频面试算法题(如果面试准备时间不够,那么集中把这些算法题做完即可,命中率高达85%+)
[外链图片转存中…(img-FzRgfSXP-1713399591001)]
[外链图片转存中…(img-Q2Vgjui4-1713399591001)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!