一、maven定义
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>gs-mysql-data</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> <version>1.4.7.RELEASE</version> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
二、application.properties定义
spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://localhost:3306/db_example spring.datasource.username=springuser spring.datasource.password=ThePassword # spring.redis.host=192.168.204.129 spring.redis.port=6379 #最大分配的对象数 spring.redis.Pool.usePool=true spring.redis.Pool.poolConfig=jedisPoolConfig spring.redis.Pool.maxIdle=10 spring.redis.Pool.maxActive=10
三、Bean定义
package hello.bean; /** * Created by Administrator on 2018/2/19. */ import javax.persistence.*; import java.io.Serializable; @Entity // This tells Hibernate to make a table out of this class @Table(name = "user") @Cacheable(true) public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String name; private String email; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
四、repository定义
package hello.repository; /** * Created by Administrator on 2018/2/19. */ import hello.bean.User; import org.springframework.data.jpa.repository.JpaRepository; // This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository // CRUD refers Create, Read, Update, Delete public interface UserRepository extends JpaRepository<User, Long> { }
五、应用定义
package hello; /** * Created by Administrator on 2018/2/19. */ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; @SpringBootApplication @EnableCaching public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
六、定义Service
package hello.controller; /** * Created by Administrator on 2018/2/19. */ import hello.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import hello.bean.User; @Controller // This means that this class is a Controller @RequestMapping(path="/demo") // This means URL's start with /demo (after Application path) public class MainController { @Autowired // This means to get the bean called userRepository // Which is auto-generated by Spring, we will use it to handle the data private UserRepository userRepository; @GetMapping(path="/add") // Map ONLY GET Requests public @ResponseBody String addNewUser (@RequestParam String name , @RequestParam String email) { // @ResponseBody means the returned String is the response, not a view name // @RequestParam means it is a parameter from the GET or POST request User n = new User(); n.setName(name); n.setEmail(email); userRepository.save(n); return "Saved"; } @GetMapping(path="/all") public @ResponseBody Iterable<User> getAllUsers() { // This returns a JSON or XML with the users return userRepository.findAll(); } }
参考:
https://spring.io/guides/gs/accessing-data-mysql/
相关推荐
spring mvc + spring data jpa + redis + shiro 集成加应用 简单的写了一个demo 如果有报CacheTranscoder.java,DesBase64Tool.java和DESPlus.java 类找不到相关的错误,直接删掉就行,这个是有关加密的算法 另外...
项目最小话配置,web maven项目,可以跑login.html。其他页面没有功能
spring-data-jpa-neo4j-redis-session 在Web App中使用Spring Data Neo4j和Spring Data JPA一起进行Spring Boot的演示Web项目 依存关系 Spring Data JPA Spring数据Neo4j Spring Boot 2.0.3。发布 Neo4j图形...
spring-data不必介绍,附件中包括spring-data一些例子,包括整合jpa,mongodb,neo4j,redis的应用,有兴趣的朋友可以参考一下。
乐聊tv 聊天 直播 rtmp springboot redis spring-data-jpa mongodb websocket 开源 起因 主要想做一个小型直播网站,用的技术不难,spring-boot框架,持久层采用spring-data-jpa, 缓存采用redis,消息聊天mongodb,...
-展示柜奥普方面spring-aop 引导程序缓存——弹簧缓存数据库米巴蒂斯蔚来米娜2 nosql redis -- jedis, spring-data-redis 序列化——msgpack,protobuf 测试单位——dbunit、easymock、junit、mockito、powermock ...
【博客个人资源】 包含前端、后端、移动开发、操作...Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes
该项目利用了基于springboot + vue + mysql的开发...Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes
博客(BIG)系统是企业营销信息化的解决方案,它将企业市场管理、销售管理、服务管理三个领域应用三位一体化,帮助企业提升整体营销管理竞争力、提高销售工作效率、提高服务满意度顾客忠诚度。以满足企业不断丰厚的...
Spring Boot实战(连接MySQL数据库+使用Spring Data Jpa+配置拦截器及实现跨域访问+整合Redis使用Docker部署Spring Boot项目+使用AOP的正确姿势+整合Mybatis并完成CRUD操作+整合 thymeleaf+整合 MyBatis (XML 版))
包含以下DEMO spring-data-book\gemfire spring-data-book\jdbc spring-data-book\jpa spring-data-book\mongodb spring-data-book\neo4j spring-data-book\querydsl spring-data-book\redis spring-data-book\rest
NULL 博文链接:https://kanpiaoxue.iteye.com/blog/1995424
springboot+springdata jpa+freemark+ajax+bootstrap+redis增删改查,本文档简单易懂,适合初学者学习使用
'SpringDataJPA从入门到精通'分为12章 内容包括整体认识JPA、JPA基础查询方法、定义查询方法、注解式查询方法、@Entity实例里面常用注解详解、JpaRepository扩展详解、JPA的MVC扩展REST支持、DataSource的配置、乐观...
本次课程以SpringData为中心,重点讲解了其JPA组件,扩展讲解了redis,mongDB,ES组件,并且对部分组件做了必要的源码分析。而且在课程的最后部分加入了一个综合案例,可以将前面章节所学知识点应用到一个项目中,帮助...
spring 实践学习案例,与其它组件结合如 mybatis、jpa、dubbo、redis、mongodb、memcached、kafka、rabbitmq、activemq、shiro等 #### 软件架构 基于Java 1.8 #### Spring 版本 - 5.0.8.RELEASE #### 模块说明 - ...
以Spring Framework为核心容器,Spring data Jpa(Hibernate实现)为数据访问层, Apache Shiro为权限框架,Redis对常用数据进行缓存,前端使用Vue全家桶,前后端分离、JWT鉴权的开源框架。 角色的功能权限控制方式为...
3、该项目采用了struts2 hibernate spring和 spring data jpa 开源框架完成,并融入了cxf开源webservice框架的应用,而这些技术都是当下流行的技术。 4、在缓存方面运用了互联网的流行技术redis实现缓存存贮,...
2. spring-boot-data-jpa 3. spring-boot-cache-simple 不使用第三方缓存技术,ConcurrentMapCacheManager,默认使用 ConcurrentHashMap作为存储缓存 4. spring-boot-cache-ehcache2 添加 ehcache2 依赖和 ehcache.
SpringBoot Data Jpa Apache Shiro Reactor Ehcache Redis Freemarker 功能 Controllers 异步 Services 异步 Dao 依赖于JDBC和ORM,暂未更改成异步 移除Druid和多数据源 TODO 链式调用,尽量去掉显示调用subscribe...