Spring Boot 中使用 jpa
本文原文版权归 CSDN Hgihness 所有,此处为转载+技术收藏,如有再转请自觉于篇头处标明原文作者及出处,这是大家对作者劳动成果的自觉尊重!!
作者:Hgihness
原文:http://blog.csdn.net/javahighness/article/details/53055149
一、maven的pom文件
- <?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>com.zsx</groupId>
- <artifactId>demo</artifactId>
- <packaging>war</packaging>
- <version>0.0.1</version>
- <name>zsx Maven Webapp</name>
- <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <jdk.version>1.7</jdk.version>
- <tomcat.version>7.0.69</tomcat.version>
- </properties>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.4.0.RELEASE</version>
- </parent>
- <dependencies>
- <!-- 添加对jsp视图解析的支持 -->
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- </dependency>
- <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-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <!-- 只需引入spring-boot-devtools 即可实现热部署 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- </dependency>
- <!-- Json包 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- <version>1.2.16</version>
- </dependency>
- <!-- 为了监控数据库 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid</artifactId>
- <version>1.0.25</version>
- </dependency>
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi</artifactId>
- <version>3.14</version>
- </dependency>
- <!-- Junit 单元测试 -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger2</artifactId>
- <version>2.6.0</version>
- </dependency>
- <dependency>
- <groupId>io.springfox</groupId>
- <artifactId>springfox-swagger-ui</artifactId>
- <version>2.6.0</version>
- </dependency>
- </dependencies>
- <build>
- <finalName>/</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <dependencies>
- <!-- 热部署 -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>springloaded</artifactId>
- <version>1.2.6.RELEASE</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
- <repositories>
- <repository>
- <id>ali</id>
- <name>ali Repository</name>
- <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
- </project>
二、项目架构
想想还是介绍一下项目的目录结构,这样方便梳理整体的架构配置
- src
- ├─main
- │ ├─java
- │ │ └─com
- │ │ └─zsx
- │ │ │ Application.java
- │ │ │ SpringBootStartApplication.java
- │ │ │
- │ │ ├─common
- │ │ │ ├─config
- │ │ │ │ DruidDBConfig.java
- │ │ │ │ MultipartConfig.java
- │ │ │ │
- │ │ │ ├─filter
- │ │ │ │ DruidStatFilter.java
- │ │ │ │
- │ │ │ ├─interceptors
- │ │ │ │ AuthInterceptor.java
- │ │ │ │ WebAppConfigurer.java
- │ │ │ │
- │ │ │ ├─servlet
- │ │ │ │ DruidStatViewServlet.java
- │ │ │ │
- │ │ │ └─swagger
- │ │ │ Swagger2.java
- │ │ │
- │ │ ├─controller
- │ │ │ │ LoginController.java
- │ │ │ │ TestController.java
- │ │ │ │ UserController.java
- │ │ │
- │ │ ├─dao
- │ │ │ │ TUserDao.java
- │ │ │ │
- │ │ │ └─impl
- │ │ ├─entity
- │ │ │ │ BaseEntity.java
- │ │ │
- │ │ ├─model
- │ │ │ │ Tree.java
- │ │ │
- │ │ ├─service
- │ │ │ │ UserService.java
- │ │ │ │
- │ │ │ └─impl
- │ │ │ UserServiceImpl.java
- │ │ │
- │ │ └─util
- │ │ GeneratePageable.java
- │ │
- │ ├─resources
- │ │ │ application.properties
- │ │ │ logback-test.xml
- │ │ │
- │ │ └─static
- │ │ ├─css
- │ │ ├─img
- │ │ └─js
- │ │
- │ └─webapp
- │ │ index.jsp
- │ │
- │ └─WEB-INF
- │ │ web.xml
- │ │
- │ └─view
- │ │ login.jsp
- │ │
- │ ├─error
- │ │ 500.jsp
- │ ├─jsp
- │ main.jsp
- │
- └─test
- └─java
- UtilTest.java
标准的maven项目结构,其中Java下是dao
、service
、controller
,还有实体类映射entity
,其他配置config
三、resources下的应用配置文件application.properties
- #server.port=9090
- # 数据库访问配置
- # 主数据源,默认的
- spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
- spring.datasource.url=jdbc:mysql://localhost:3306/test
- spring.datasource.username= root
- spring.datasource.password= root
- spring.datasource.driverClassName = com.mysql.jdbc.Driver
- # 下面为连接池的补充设置,应用到上面所有数据源中
- # 初始化大小,最小,最大
- spring.datasource.initialSize=5
- spring.datasource.minIdle=5
- spring.datasource.maxActive=20
- # 配置获取连接等待超时的时间
- spring.datasource.maxWait=60000
- # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
- spring.datasource.timeBetweenEvictionRunsMillis=60000
- # 配置一个连接在池中最小生存的时间,单位是毫秒
- spring.datasource.minEvictableIdleTimeMillis=300000
- spring.datasource.validationQuery=SELECT 1 FROM DUAL
- spring.datasource.testWhileIdle=true
- spring.datasource.testOnBorrow=false
- spring.datasource.testOnReturn=false
- # 打开PSCache,并且指定每个连接上PSCache的大小
- spring.datasource.poolPreparedStatements=true
- spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
- # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
- spring.datasource.filters=stat,wall,log4j
- # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
- spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
- # 合并多个DruidDataSource的监控数据
- spring.datasource.useGlobalDataSourceStat=true
- #JPA Configuration:
- spring.jpa.database=MYSQL
- # Show or not log for each sql query
- spring.jpa.show-sql=false
- spring.jpa.generate-ddl=true
- # Hibernate ddl auto (create, create-drop, update)
- spring.jpa.hibernate.ddl-auto=create
- #spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
- spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
- #spring.jpa.database=org.hibernate.dialect.MySQL5InnoDBDialect
- spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
- spring.mvc.view.prefix=/WEB-INF/view/
- spring.mvc.view.suffix=.jsp
- #spring.resources.static-locations=classpath:/resources/,classpath:/static/
四、启动应用主类文件 Application.java
- package com.zsx;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.web.servlet.ServletComponentScan;
- @SpringBootApplication
- @ServletComponentScan // 扫描使用注解方式的servlet
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
- }
- 若需要部署到外部的tomcat容器中,则添加下面类即可。
- package com.zsx;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.boot.context.web.SpringBootServletInitializer;
- /**
- * 修改启动类,继承 SpringBootServletInitializer 并重写 configure 方法
- * @author ZSX
- *
- */
- public class SpringBootStartApplication extends SpringBootServletInitializer {
- private static final Logger logger = LoggerFactory.getLogger(SpringBootStartApplication.class);
- @Override
- protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
- return builder.sources(Application.class);
- }
- }
五、数据库连接池Druid的配置
- package com.zsx.common.config;
- import java.sql.SQLException;
- import javax.sql.DataSource;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.context.annotation.Primary;
- import com.alibaba.druid.pool.DruidDataSource;
- /**
- * DruidDBConfig类被@Configuration标注,用作配置信息;
- * DataSource对象被@Bean声明,为Spring容器所管理,
- * @Primary表示这里定义的DataSource将覆盖其他来源的DataSource。
- * @author ZSX
- *jdbc.url=${jdbc.url}
- *最新的支持方式如下:
- *jdbc.url=@jdbc.url@
- */
- @Configuration
- public class DruidDBConfig {
- // private Logger logger = LoggerFactory.getLogger(DruidDBConfig.class);
- @Value("${spring.datasource.url}")
- private String dbUrl;
- @Value("${spring.datasource.username}")
- private String username;
- @Value("${spring.datasource.password}")
- private String password;
- @Value("${spring.datasource.driverClassName}")
- private String driverClassName;
- @Value("${spring.datasource.initialSize}")
- private int initialSize;
- @Value("${spring.datasource.minIdle}")
- private int minIdle;
- @Value("${spring.datasource.maxActive}")
- private int maxActive;
- @Value("${spring.datasource.maxWait}")
- private int maxWait;
- @Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
- private int timeBetweenEvictionRunsMillis;
- @Value("${spring.datasource.minEvictableIdleTimeMillis}")
- private int minEvictableIdleTimeMillis;
- @Value("${spring.datasource.validationQuery}")
- private String validationQuery;
- @Value("${spring.datasource.testWhileIdle}")
- private boolean testWhileIdle;
- @Value("${spring.datasource.testOnBorrow}")
- private boolean testOnBorrow;
- @Value("${spring.datasource.testOnReturn}")
- private boolean testOnReturn;
- @Value("${spring.datasource.poolPreparedStatements}")
- private boolean poolPreparedStatements;
- @Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
- private int maxPoolPreparedStatementPerConnectionSize;
- @Value("${spring.datasource.filters}")
- private String filters;
- @Value("{spring.datasource.connectionProperties}")
- private String connectionProperties;
- @Bean // 声明其为Bean实例
- @Primary // 在同样的DataSource中,首先使用被标注的DataSource
- public DataSource dataSource() {
- DruidDataSource datasource = new DruidDataSource();
- datasource.setUrl(this.dbUrl);
- datasource.setUsername(username);
- datasource.setPassword(password);
- datasource.setDriverClassName(driverClassName);
- // configuration
- datasource.setInitialSize(initialSize);
- datasource.setMinIdle(minIdle);
- datasource.setMaxActive(maxActive);
- datasource.setMaxWait(maxWait);
- datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
- datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
- datasource.setValidationQuery(validationQuery);
- datasource.setTestWhileIdle(testWhileIdle);
- datasource.setTestOnBorrow(testOnBorrow);
- datasource.setTestOnReturn(testOnReturn);
- datasource.setPoolPreparedStatements(poolPreparedStatements);
- datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
- try {
- datasource.setFilters(filters);
- } catch (SQLException e) {
- }
- datasource.setConnectionProperties(connectionProperties);
- return datasource;
- }
- }
- springboot里默认使用tomcat的上传文件大小限制,即1MB,
- 修改用下面的配置类:
- import javax.servlet.MultipartConfigElement;
- import org.springframework.boot.web.servlet.MultipartConfigFactory;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- @Configuration
- public class MultipartConfig {
- @Bean
- public MultipartConfigElement multipartConfigElement(){
- MultipartConfigFactory factory = new MultipartConfigFactory();
- factory.setMaxFileSize("10MB");
- factory.setMaxRequestSize("10MB");
- return factory.createMultipartConfig();
- }
- }
六、开启Druid的数据库监控配置
1、配置Filter
- import javax.servlet.annotation.WebFilter;
- import javax.servlet.annotation.WebInitParam;
- import com.alibaba.druid.support.http.WebStatFilter;
- /**
- * 配置druid监控统计功能
- * 配置Filter
- * @author ZSX
- *
- */
- @WebFilter(filterName = "druidWebStatFilter", urlPatterns = "/*",
- initParams = {
- @WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
- }
- )
- public class DruidStatFilter extends WebStatFilter {
- }
2、 配置web访问的servlet
- import javax.servlet.annotation.WebInitParam;
- import javax.servlet.annotation.WebServlet;
- import com.alibaba.druid.support.http.StatViewServlet;
- /**
- * 配置druid监控统计功能
- * 在SpringBoot项目中基于注解的配置,如果是web.xml配置,按规则配置即可
- * @author ZSX
- *
- */
- @WebServlet(urlPatterns = "/druid/*",
- initParams = {
- // @WebInitParam(name = "allow", value = "192.168.16.110,127.0.0.1"), // IP白名单 (没有配置或者为空,则允许所有访问)
- // @WebInitParam(name="deny",value="192.168.16.111"), // IP黑名单 (存在共同时,deny优先于allow)
- @WebInitParam(name="loginUsername",value="druid"),// 用户名
- @WebInitParam(name="loginPassword",value="druid"),// 密码
- @WebInitParam(name="resetEnable",value="false")// 禁用HTML页面上的“Reset All”功能
- }
- )
- public class DruidStatViewServlet extends StatViewServlet {
- }
这样启动项目后在浏览器中输入地址:端口/druid
,就可以看到druid的监控web页面了
七、 拦截器配置
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
- import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
- @Configuration
- public class WebAppConfigurer extends WebMvcConfigurerAdapter {
- /**
- * 配置拦截器
- */
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- // TODO Auto-generated method stub
- // 多个拦截器组成一个拦截器链
- // addPathPatterns 用于添加拦截规则
- // excludePathPatterns 用户排除拦截
- registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/**");
- super.addInterceptors(registry);
- }
- /**
- * 添加自定义的静态资源映射
- 这里使用代码的方式自定义目录映射,并不影响Spring Boot的默认映射,可以同时使用。
- */
- @Override
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
- // registry.addResourceHandler("/new/**").addResourceLocations("classpath:/new/");
- // registry.addResourceHandler("/**").addResourceLocations("/");
- super.addResourceHandlers(registry);
- }
- }
八、swagger发布api测试配置(可忽略)
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import springfox.documentation.builders.ApiInfoBuilder;
- import springfox.documentation.builders.PathSelectors;
- import springfox.documentation.builders.RequestHandlerSelectors;
- import springfox.documentation.service.ApiInfo;
- import springfox.documentation.spi.DocumentationType;
- import springfox.documentation.spring.web.plugins.Docket;
- import springfox.documentation.swagger2.annotations.EnableSwagger2;
- @Configuration
- @EnableSwagger2
- public class Swagger2 {
- @Bean
- public Docket createRestApi(){
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage("com.zsx.controller.api"))
- .paths(PathSelectors.any())
- .build();
- }
- private ApiInfo apiInfo(){
- return new ApiInfoBuilder()
- .title("Spring Boot中使用Swagger2构建RESTful APIs")
- .description("描述")
- .termsOfServiceUrl("http://zsx.com.cn")
- .version("1.0")
- .build();
- }
- }
至此,所有的配置已完成,下面是一个操作数据的简单demo
九、实体类
- @Entity
- @Table(name = "t_user")
- public class Tuser implements java.io.Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy=GenerationType.IDENTITY)
- private Long id;
- @Column(name = "username")
- private String userName;
- @Column(name = "password")
- private String passWord;
- @Column(name = "email")
- private String email;
- @Column(name = "mobile")
- private String mobile;
- @Column(name = "nickname")
- private String nickName;
- // 省略getter 和 setter
- }
十、dao层
1、使用jpa基本可以实现不写sql,(但实际开发中,业务逻辑会很复杂,一点不写sql完全不现实)
2、注意添加
@Repository
注解, 添加JpaSpecificationExecutor
继承可以方便分页3、 看些jpa的查询语法资料
- import java.util.List;
- import java.util.Map;
- import org.springframework.data.domain.Pageable;
- import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
- import org.springframework.data.jpa.repository.Query;
- import org.springframework.data.repository.PagingAndSortingRepository;
- import org.springframework.data.repository.query.Param;
- import org.springframework.stereotype.Repository;
- @Repository
- public interface TuserDao extends PagingAndSortingRepository<Tuser, Long>, JpaSpecificationExecutor<Tuser> {
- Tuser findByUserName(String userName);
- @Query("from Tuser t where id = :id")
- List<Tuser> queryFamilyList(@Param("id") Long id, Pageable pageable);
- }
十一、service和controller没啥好说的,跟原先的一样,下面再提供一个单元测试的demo
- import java.util.List;
- import javax.persistence.EntityManager;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.SpringApplicationConfiguration;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.web.WebAppConfiguration;
- import com.alibaba.fastjson.JSON;
- import com.golden.Application;
- import com.golden.dao.TUserDao;
- import com.golden.entity.Tuser;
- import com.golden.util.GeneratePageable;
- @RunWith(SpringJUnit4ClassRunner.class)
- //指定我们SpringBoot工程的Application启动类
- @SpringApplicationConfiguration(classes = Application.class)
- //由于是Web项目,Junit需要模拟ServletContext,因此我们需要给我们的测试类加上@WebAppConfiguration
- @WebAppConfiguration
- public class UtilTest {
- @Autowired
- private TUserDao dao;
- @Autowired
- private EntityManager em;
- @Test
- public void test1(){
- dao.findByUserName("admin");
- }
- @Test
- public void test2(){
- // 使用jpa提供的分页类
- java.util.List<Order> list = new ArrayList<Sort.Order>();
- Order order = new Order(Direction.DESC, "createTime");
- list.add(order);
- Sort sort = new Sort(list);
- Pageable pageable = new PageRequest(0, 10, sort);
- Page<Tuser> findAll = dao.findAll(pageable);
- }
- @Test
- public void test3(){
- EntityManager em = dao.getEntityManager();
- Query query = em.createNativeQuery("select * from t_user limit 1");
- Object singleResult = query.getSingleResult();
- System.out.println(singleResult);
- }
- /*
- //执行原生SQL
- Query nativeQuery = em.createNativeQuery(String sql);
- //指定返回对象类型
- nativeQuery.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean( Class resultType));
- //返回对象
- List<T> resultList = nativeQuery.getResultList();
- */
- }
后记:
不用Druid的可以把有关Druid的配置全部删掉,swagger的同理
这里没有使用
hibernate.cfg.xml
配置文件,主要习惯了在实体类里配置字段了,不怎么用hibernate的映xml文件了,但其实配置起来跟springmvc项目一样说实话这里使用jpa操作数据库,没感觉有多方便,因为总有各种奇葩的需求,当然也可能是我没深入研究,所以建议改用Mybatis,这个我会再写一篇springboot加mybatis的配置教程的,最后,还可以使用原生的sql查询,即使用单元测试里的
EntityManager
对象去执行sql,返回结果可以指定对象类型,也很方便还需要注意的一个点是静态文件的存放位置,这个跟原先的项目不一样,原先是在webapp下,但springboot是默认放在resources下的static目录下的,还有其他默认目录和配置,自行搜索
时间仓促,以后再补充
Spring Boot 中使用 jpa的更多相关文章
- 初识在Spring Boot中使用JPA
前面关于Spring Boot的文章已经介绍了很多了,但是一直都没有涉及到数据库的操作问题,数据库操作当然也是我们在开发中无法回避的问题,那么今天我们就来看看Spring Boot给我们提供了哪些疯狂 ...
- 使用spring boot中的JPA操作数据库
前言 Spring boot中的JPA 使用的同学都会感觉到他的强大,简直就是神器一般,通俗的说,根本不需要你写sql,这就帮你节省了很多时间,那么下面我们来一起来体验下这款神器吧. 一.在pom中添 ...
- Spring Boot中使用Jpa的findOne方法不能传入id
最近通过慕课网学习spring boot,视频中通过jpa的findOne方法以id为参数查询出对应的信息, 而当我自己做测试的时候却发现我的findOne方法的参数没有Integer类型的id,而是 ...
- spring boot 中使用 jpa以及jpa介绍
1.什么是jpa呢?JPA顾名思义就是Java Persistence API的意思,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中.12.jpa具有什么 ...
- spring boot中注入jpa时报could not autowire.No beans of 'PersonRepository' type found
解决方法,在repository加一个注解.如下图所示: @Component
- Spring boot中应用jpa jpa用法
https://blog.csdn.net/u012582402/article/details/78717705
- 在Spring Boot中使用数据缓存
春节就要到了,在回家之前要赶快把今年欠下的技术债还清.so,今天继续.Spring Boot前面已经预热了n篇博客了,今天我们来继续看如何在Spring Boot中解决数据缓存问题.本篇博客是以初识在 ...
- 在Spring Boot中使用数据库事务
我们在前面已经分别介绍了如何在Spring Boot中使用JPA(初识在Spring Boot中使用JPA)以及如何在Spring Boot中输出REST资源(在Spring Boot中输出REST资 ...
- 在Spring Boot中输出REST资源
前面我们我们已经看了Spring Boot中的很多知识点了,也见识到Spring Boot带给我们的各种便利了,今天我们来看看针对在Spring Boot中输出REST资源这一需求,Spring Bo ...
随机推荐
- JSP中系统Date的几点不符合中国时间观的地方
正常调用系统时间的显示格式是Date date = new Date 显示出来的当前时间为Sun Nov 22 18:39:51 CST 2015 星期天的英文单词是Sun, 这个大家都是熟悉的, 这 ...
- svn版本分支及冲突解决笔记
转载:http://blog.csdn.net/xuguiyi100/article/details/51966557 分支合并主干示例 1.主干工程右键选择merge合并下一步 2.选中merge ...
- mybatis框架入门程序:演示通过mybatis实现数据库的模糊查询操作
1. mybatis的基本准备操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10149480.html 2. 根据用户名查询用户信息: (1)映射文件 ...
- Golang之匿名函数和闭包
Go语言支持匿名函数,即函数可以像普通变量一样被传递或使用. 使用方法如下: main.go package main import ( "fmt" ) func main() { ...
- Java 设计模式系列(二十)状态模式
Java 设计模式系列(二十)状态模式 状态模式,又称状态对象模式(Pattern of Objects for States),状态模式是对象的行为模式.状态模式允许一个对象在其内部状态改变的时候改 ...
- HDU 6065 RXD, tree and sequence (LCA+DP)
题意:给定上一棵树和一个排列,然后问你把这个排列分成m个连续的部分,每个部分的大小的是两两相邻的LCA的最小深度,问你最小是多少. 析:首先这个肯定是DP,然后每个部分其实就是里面最小的那个LCA的深 ...
- 使用electron-packager electron-builder electron-updater 打包vue项目,支持在线更新
1.如何用electron-packager electron-builder打包vue项目,打包成桌面程序. 步骤一. 执行npm run build 打包你的vue项目. 打包成功后,生成dist ...
- .NET基础 (20).NET中的数据库开发
ADO NET和数据库程序基础1 什么是关系型数据库2 如何通过SQL语句来实现行列转换3 ADO NET支持哪几种数据源 ADO NET和数据库的连接1 请简要叙述数据库连接池的机制2 如何提高连接 ...
- Vivado 2017封装自定义IP Core
使用Vivado2017.3自定义IP Core.通常情况下,我们做设计采用模块化设计,对于已经设计好的一部分模块功能,就可以直接拿来调用,IP Core就是这样来的,一般来说我们看不到IP Core ...
- 第二周leetcode
4/4 这周莫名得忙,一天是做编译,一天是做模式识别作业,(一天刷魔兽皮肤),周末玩了两天,总的来说还是松懈了,大概只做了两天的leetcode,刷了10道题,羞愧羞愧. 决定每次把代码附上在这个总结 ...