├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── libraries
│ ├── Maven__ognl_ognl_3_0_8.xml
│ ├── Maven__junit_junit_4_12.xml
│ ├── Maven__antlr_antlr_2_7_7.xml
│ ├── Maven__dom4j_dom4j_1_6_1.xml
│ ├── Maven__com_alibaba_druid_1_0_11.xml
│ ├── Maven__org_yaml_snakeyaml_1_14.xml
│ ├── Maven__redis_clients_jedis_2_5_2.xml
│ ├── Maven__xml_apis_xml_apis_1_0_b2.xml
│ ├── Maven__org_objenesis_objenesis_2_1.xml
│ ├── Maven__aopalliance_aopalliance_1_0.xml
│ ├── Maven__org_aspectj_aspectjrt_1_8_6.xml
│ ├── Maven__org_slf4j_slf4j_api_1_7_12.xml
│ ├── Maven__com_fasterxml_classmate_1_0_0.xml
│ ├── Maven__org_jboss_jandex_1_1_0_Final.xml
│ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml
│ ├── Maven__org_slf4j_jul_to_slf4j_1_7_12.xml
│ ├── Maven__org_aspectj_aspectjweaver_1_8_6.xml
│ ├── Maven__ch_qos_logback_logback_core_1_1_3.xml
│ ├── Maven__org_mockito_mockito_core_1_10_19.xml
│ ├── Maven__org_slf4j_jcl_over_slf4j_1_7_12.xml
│ ├── Maven__org_hamcrest_hamcrest_library_1_3.xml
│ ├── Maven__org_javassist_javassist_3_18_1_GA.xml
│ ├── Maven__org_apache_commons_commons_pool2_2_2.xml
│ ├── Maven__org_apache_tomcat_tomcat_jdbc_8_0_23.xml
│ ├── Maven__org_apache_tomcat_tomcat_juli_8_0_23.xml
│ ├── Maven__org_slf4j_log4j_over_slf4j_1_7_12.xml
│ ├── Maven__ch_qos_logback_logback_classic_1_1_3.xml
│ ├── Maven__mysql_mysql_connector_java_5_1_35.xml
│ ├── Maven__org_thymeleaf_thymeleaf_2_1_4_RELEASE.xml
│ ├── Maven__org_unbescape_unbescape_1_1_0_RELEASE.xml
│ ├── Maven__org_jboss_logging_jboss_logging_3_1_3_GA.xml
│ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_4_6.xml
│ ├── Maven__org_hibernate_hibernate_core_4_3_10_Final.xml
│ ├── Maven__org_springframework_spring_tx_4_1_7_RELEASE.xml
│ ├── Maven__javax_transaction_javax_transaction_api_1_2.xml
│ ├── Maven__javax_validation_validation_api_1_1_0_Final.xml
│ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_8_0_23.xml
│ ├── Maven__org_springframework_spring_aop_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_spring_orm_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_spring_web_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_spring_core_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_spring_jdbc_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_spring_test_4_1_7_RELEASE.xml
│ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_4_6.xml
│ ├── Maven__org_springframework_spring_beans_4_1_7_RELEASE.xml
│ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_8_0_23.xml
│ ├── Maven__org_springframework_spring_webmvc_4_1_7_RELEASE.xml
│ ├── Maven__org_hibernate_hibernate_validator_5_1_3_Final.xml
│ ├── Maven__org_thymeleaf_thymeleaf_spring4_2_1_4_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_spring_aspects_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_spring_context_4_1_7_RELEASE.xml
│ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_4_6.xml
│ ├── Maven__org_springframework_spring_expression_4_1_7_RELEASE.xml
│ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_0_23.xml
│ ├── Maven__nz_net_ultraq_thymeleaf_thymeleaf_layout_dialect_1_2_9.xml
│ ├── Maven__org_hibernate_hibernate_entitymanager_4_3_10_Final.xml
│ ├── Maven__org_springframework_data_spring_data_jpa_1_7_3_RELEASE.xml
│ ├── Maven__org_apache_tomcat_embed_tomcat_embed_logging_juli_8_0_23.xml
│ ├── Maven__org_springframework_data_spring_data_redis_1_4_3_RELEASE.xml
│ ├── Maven__org_jboss_logging_jboss_logging_annotations_1_2_0_Beta1.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_data_spring_data_commons_1_9_3_RELEASE.xml
│ ├── Maven__org_springframework_spring_context_support_4_1_7_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_aop_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_web_1_2_5_RELEASE.xml
│ ├── Maven__org_hibernate_javax_persistence_hibernate_jpa_2_1_api_1_0_0_Final.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_jdbc_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_test_1_2_5_RELEASE.xml
│ ├── Maven__org_hibernate_common_hibernate_commons_annotations_4_0_5_Final.xml
│ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_redis_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_logging_1_2_5_RELEASE.xml
│ ├── Maven__org_springframework_boot_spring_boot_starter_data_jpa_1_2_5_RELEASE.xml
│ └── Maven__org_springframework_boot_spring_boot_starter_thymeleaf_1_2_5_RELEASE.xml
├── compiler.xml
└── misc.xml
├── src
├── main
│ ├── resources
│ │ ├── application.properties
│ │ ├── templates
│ │ │ ├── testredis.html
│ │ │ ├── result.html
│ │ │ ├── listall.html
│ │ │ ├── index.html
│ │ │ ├── input.html
│ │ │ └── listpage.html
│ │ └── application-dev.properties
│ └── java
│ │ └── com
│ │ └── jvmhub
│ │ └── springboot
│ │ ├── repository
│ │ ├── PostRepository.java
│ │ └── ThingRepository.java
│ │ ├── form
│ │ └── Post.java
│ │ ├── service
│ │ ├── CacheDemoService.java
│ │ └── impl
│ │ │ └── CacheDemoServiceImpl.java
│ │ ├── validate
│ │ ├── Money.java
│ │ └── MoneyValidator.java
│ │ ├── SpringBootThymeleafApplication.java
│ │ ├── domain
│ │ ├── PostEntity.java
│ │ ├── Post.java
│ │ └── Thing.java
│ │ ├── aspect
│ │ └── ExecutionTimeLogger.java
│ │ ├── redis
│ │ ├── RedisConfig.java
│ │ └── RedisUtil.java
│ │ ├── druid
│ │ └── DruidConfiguration.java
│ │ └── controller
│ │ └── Home.java
└── test
│ └── java
│ └── com
│ └── jvmhub
│ └── springboot
│ └── SpringBootThymeleafApplicationTests.java
├── bootdemo.log
├── README.md
├── .project
├── pom.xml
├── pom.xml.bak
├── .classpath
└── spring-boot-thymeleaf-jpa.iml
/.idea/.name:
--------------------------------------------------------------------------------
1 | spring-boot-thymeleaf-jpa
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.profiles.active=dev
--------------------------------------------------------------------------------
/src/main/resources/templates/testredis.html:
--------------------------------------------------------------------------------
1 | hello
2 |
--------------------------------------------------------------------------------
/bootdemo.log:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jiangzhongke/spring-boot-thymeleaf-jpa/HEAD/bootdemo.log
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spring-Boot-with-Thymeleaf-part-3-Spring-Data-JPA
2 | Spring Boot with Thymeleaf tutorial, part 3 - Spring Data JPA All tutorial you can find on jvmhub.com -> http://jvmhub.com/2015/08/09/spring-boot-with-thymeleaf-tutorial-part-3-spring-data-jpa/
3 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/repository/PostRepository.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.repository;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.cache.annotation.Cacheable;
6 | import org.springframework.data.repository.CrudRepository;
7 |
8 | import com.jvmhub.springboot.domain.Post;
9 |
10 |
11 |
12 | public interface PostRepository extends CrudRepository {
13 | List findByTitle(String title);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__ognl_ognl_3_0_8.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__junit_junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__antlr_antlr_2_7_7.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__dom4j_dom4j_1_6_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | spring-boot-thymeleaf-jpa
4 | SpringBoot Portal. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.
5 |
6 |
7 |
8 | org.eclipse.jdt.core.javabuilder
9 |
10 |
11 |
12 | org.eclipse.jdt.core.javanature
13 |
14 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_alibaba_druid_1_0_11.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_yaml_snakeyaml_1_14.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__redis_clients_jedis_2_5_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_aspectj_aspectjrt_1_8_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_fasterxml_classmate_1_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_jboss_jandex_1_1_0_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/form/Post.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.form;
2 |
3 | import javax.validation.constraints.Size;
4 |
5 | public class Post {
6 |
7 | @Size(min=4, max=35)
8 | private String title;
9 |
10 | @Size(min=30, max= 1000)
11 | private String content;
12 |
13 | public String getTitle() {
14 | return title;
15 | }
16 |
17 | public void setTitle(String title) {
18 | this.title = title;
19 | }
20 |
21 | public String getContent() {
22 | return content;
23 | }
24 |
25 | public void setContent(String content) {
26 | this.content = content;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_8_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_javassist_javassist_3_18_1_GA.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_tomcat_tomcat_jdbc_8_0_23.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_tomcat_tomcat_juli_8_0_23.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_35.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/templates/result.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Boot and Thymeleaf example
5 |
6 |
7 |
8 | Spring Boot and Thymeleaf, part 3 - SPRING DATA JPA
9 |
10 |
ID:
11 |
12 | Title:
13 |
14 | Content:
15 |
16 | ---------------------------------------------------------
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_thymeleaf_thymeleaf_2_1_4_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_unbescape_unbescape_1_1_0_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_1_3_GA.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/service/CacheDemoService.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.domain.Page;
6 | import org.springframework.data.domain.Pageable;
7 |
8 | import com.jvmhub.springboot.domain.Thing;
9 |
10 |
11 |
12 | public interface CacheDemoService {
13 | public void create(Thing thing);
14 | public Thing findById(Long id);
15 | public Iterable findAll();
16 | public Iterable findByTitle(String title);
17 | public Thing update(Thing thing);
18 | public void delete(Long id);
19 |
20 | public Page findByPage(Pageable pageable);
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hibernate_hibernate_core_4_3_10_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_tx_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__javax_transaction_javax_transaction_api_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_el_8_0_23.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_aop_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_orm_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_web_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_core_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_jdbc_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_test_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/validate/Money.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.validate;
2 |
3 |
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | import javax.validation.Constraint;
10 | import javax.validation.Payload;
11 |
12 |
13 | @Target({ElementType.FIELD, ElementType.METHOD})
14 | @Retention(RetentionPolicy.RUNTIME)
15 | @Constraint(validatedBy=MoneyValidator.class)
16 | public @interface Money {
17 |
18 | String message() default"不是金额形式";
19 |
20 | Class>[] groups() default {};
21 |
22 | Class extends Payload>[] payload() default {};
23 |
24 | }
--------------------------------------------------------------------------------
/src/main/resources/templates/listall.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Boot and Thymeleaf example
5 |
6 |
7 |
8 | Spring Boot and Thymeleaf, part 3 - SPRING DATA JPA
9 |
10 |
ID:
11 |
12 | Title:
13 |
14 | Content:
15 |
16 | 删除
17 | ---------------------------------------------------------
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_beans_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_core_8_0_23.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_webmvc_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hibernate_hibernate_validator_5_1_3_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_thymeleaf_thymeleaf_spring4_2_1_4_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_aspects_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_context_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_4_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_expression_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_0_23.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__nz_net_ultraq_thymeleaf_thymeleaf_layout_dialect_1_2_9.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hibernate_hibernate_entitymanager_4_3_10_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_data_spring_data_jpa_1_7_3_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_logging_juli_8_0_23.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_data_spring_data_redis_1_4_3_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_jboss_logging_jboss_logging_annotations_1_2_0_Beta1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_9_3_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_spring_context_support_4_1_7_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_aop_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_1_api_1_0_0_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_hibernate_common_hibernate_commons_annotations_4_0_5_Final.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_redis_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_tomcat_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_jpa_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_thymeleaf_1_2_5_RELEASE.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/validate/MoneyValidator.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.validate;
2 |
3 |
4 | import java.math.BigDecimal;
5 | import java.util.regex.Pattern;
6 |
7 | import javax.validation.ConstraintValidator;
8 | import javax.validation.ConstraintValidatorContext;
9 | public class MoneyValidator implements ConstraintValidator {
10 |
11 | private String moneyReg = "^\\d+(\\.\\d{1,2})?$";//表示金额的正则表达式
12 | private Pattern moneyPattern = Pattern.compile(moneyReg);
13 |
14 | public void initialize(Money money) {
15 | // TODO Auto-generated method stub
16 |
17 | }
18 |
19 | public boolean isValid(BigDecimal value, ConstraintValidatorContext arg1) {
20 | // TODO Auto-generated method stub
21 | if (value == null)
22 | return true;
23 | return moneyPattern.matcher(value.toString()).matches();
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/SpringBootThymeleafApplication.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.annotation.ComponentScan;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
9 | import org.springframework.context.annotation.ImportResource;
10 | import org.springframework.scheduling.annotation.EnableScheduling;
11 |
12 | @SpringBootApplication
13 | @EnableAspectJAutoProxy
14 | public class SpringBootThymeleafApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(SpringBootThymeleafApplication.class, args);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Boot and Thymeleaf example
5 |
6 |
7 |
8 | Spring Boot and Thymeleaf, part 2 - forms
9 |
26 |
27 |
--------------------------------------------------------------------------------
/src/main/resources/templates/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Boot and Thymeleaf example
5 |
6 |
7 |
8 | Spring Boot and Thymeleaf, part 2 - forms
9 |
26 |
27 |
--------------------------------------------------------------------------------
/src/main/resources/templates/listpage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Boot and Thymeleaf example
5 |
6 |
7 |
8 | Spring Boot and Thymeleaf, part 3 - SPRING DATA JPA
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
ID:
21 |
22 | Title:
23 |
24 | Content:
25 |
26 | 删除
27 | ---------------------------------------------------------
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/domain/PostEntity.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.domain;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.GeneratedValue;
5 | import javax.persistence.GenerationType;
6 | import javax.persistence.Id;
7 |
8 | @Entity
9 | public class PostEntity {
10 |
11 | public PostEntity() {}
12 |
13 | public PostEntity(String title, String content) {
14 | this.title = title;
15 | this.content = content;
16 | }
17 |
18 | @Id
19 | @GeneratedValue(strategy = GenerationType.AUTO)
20 | private int id;
21 |
22 | private String title;
23 |
24 | private String content;
25 |
26 | public int getId() {
27 | return id;
28 | }
29 | public void setId(int id) {
30 | this.id = id;
31 | }
32 | public String getTitle() {
33 | return title;
34 | }
35 | public void setTitle(String title) {
36 | this.title = title;
37 | }
38 | public String getContent() {
39 | return content;
40 | }
41 | public void setContent(String content) {
42 | this.content = content;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/domain/Post.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.domain;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.GeneratedValue;
5 | import javax.persistence.GenerationType;
6 | import javax.persistence.Id;
7 | import javax.validation.constraints.Size;
8 |
9 | @Entity
10 | public class Post {
11 |
12 | public Post() {}
13 |
14 | public Post(String title, String content) {
15 | this.title = title;
16 | this.content = content;
17 | }
18 |
19 | @Id
20 | @GeneratedValue(strategy = GenerationType.AUTO)
21 | private int id;
22 |
23 | @Size(min=4, max=35)
24 | private String title;
25 |
26 | @Size(min=30, max= 1000)
27 | private String content;
28 |
29 | public int getId() {
30 | return id;
31 | }
32 | public void setId(int id) {
33 | this.id = id;
34 | }
35 | public String getTitle() {
36 | return title;
37 | }
38 | public void setTitle(String title) {
39 | this.title = title;
40 | }
41 | public String getContent() {
42 | return content;
43 | }
44 | public void setContent(String content) {
45 | this.content = content;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/repository/ThingRepository.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.repository;
2 |
3 | import java.util.Date;
4 | import java.util.Iterator;
5 | import java.util.List;
6 |
7 | import org.springframework.data.domain.Page;
8 | import org.springframework.data.domain.Pageable;
9 | import org.springframework.data.jpa.repository.JpaRepository;
10 | import org.springframework.data.jpa.repository.Query;
11 | import org.springframework.data.repository.CrudRepository;
12 | import org.springframework.data.repository.PagingAndSortingRepository;
13 |
14 | import com.jvmhub.springboot.domain.Thing;
15 |
16 | public interface ThingRepository extends JpaRepository {
17 | @Query("select u from Thing u where u.title like ?1%")
18 | Iterable findByTitle(String title);
19 | //自動生成,無序實現
20 | List findByContentLike(String content);
21 | List findByDatefieldGreaterThan(Date datefield);
22 | List findByDatefieldBetween(Date begindate,Date enddate);
23 |
24 | //返回部分字段
25 | @Query(value="select new Thing(u.id,u.title) from Thing u")
26 | Page findPartFields(Pageable pageable);
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/aspect/ExecutionTimeLogger.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.aspect;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.annotation.After;
5 | import org.aspectj.lang.annotation.Around;
6 | import org.aspectj.lang.annotation.Aspect;
7 | import org.aspectj.lang.annotation.Before;
8 | import org.aspectj.lang.annotation.Pointcut;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 | import org.springframework.stereotype.Component;
12 | import org.springframework.util.StopWatch;
13 |
14 | @Aspect
15 | @Component
16 | public class ExecutionTimeLogger {
17 |
18 | private Logger logger;
19 |
20 | public ExecutionTimeLogger() {
21 | logger = LoggerFactory.getLogger(getClass());
22 | logger.info("HEY");
23 | }
24 |
25 | //@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
26 | //public void requestMapping() {}
27 |
28 | //@Pointcut("execution(* com.jvmhub.springboot.service.impl.*ServiceImpl.*(..))")
29 | @Pointcut("execution(* com.jvmhub.springboot.repository..*.*(..))")
30 | public void methodPointcut() {}
31 |
32 |
33 | //@Around("requestMapping() && methodPointcut()")
34 | @Around("methodPointcut()")
35 | public Object profile(ProceedingJoinPoint pjp) throws Throwable {
36 | StopWatch sw = new StopWatch();
37 | String name = pjp.getSignature().getName();
38 | try {
39 | sw.start();
40 | return pjp.proceed();
41 | } finally {
42 | sw.stop();
43 | logger.info("STOPWATCH: " + sw.getTotalTimeMillis() + " - " + name);
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.jvmhub
7 | spring-boot-thymeleaf-jpa
8 | 0.0.1
9 | jar
10 |
11 | bootportal
12 | SpringBoot Portal
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.2.5.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | 1.7
24 |
25 | 1.0.11
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-thymeleaf
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-data-jpa
41 |
42 |
43 |
44 | mysql
45 | mysql-connector-java
46 |
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-redis
51 |
52 |
53 | com.alibaba
54 | druid
55 | ${druid.version}
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-maven-plugin
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/pom.xml.bak:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.jvmhub
7 | spring-boot-thymeleaf-jpa
8 | 0.0.1
9 | jar
10 |
11 | bootportal
12 | SpringBoot Portal
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.2.5.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | 1.8
24 |
25 | 1.0.11
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-thymeleaf
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-data-jpa
41 |
42 |
43 |
44 | mysql
45 | mysql-connector-java
46 |
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-redis
51 |
52 |
53 | com.alibaba
54 | druid
55 | ${druid.version}
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-maven-plugin
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | 1.7
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/service/impl/CacheDemoServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.service.impl;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.cache.annotation.CacheEvict;
7 | import org.springframework.cache.annotation.CachePut;
8 | import org.springframework.cache.annotation.Cacheable;
9 | import org.springframework.data.domain.Page;
10 | import org.springframework.data.domain.Pageable;
11 | import org.springframework.stereotype.Service;
12 |
13 | import com.jvmhub.springboot.domain.Thing;
14 | import com.jvmhub.springboot.repository.ThingRepository;
15 | import com.jvmhub.springboot.service.CacheDemoService;
16 |
17 | @Service
18 | public class CacheDemoServiceImpl implements CacheDemoService {
19 |
20 | /**
21 | * 缓存的key
22 | */
23 | public static final String THING_ALL_KEY = "\"thing_all\"";
24 | /**
25 | * value属性表示使用哪个缓存策略,缓存策略在ehcache.xml
26 | */
27 | public static final String DEMO_CACHE_NAME = "demo";
28 |
29 | @Autowired
30 | public ThingRepository data;
31 |
32 | @CacheEvict(value = DEMO_CACHE_NAME, key = THING_ALL_KEY)
33 | @Override
34 | public void create(Thing thing) {
35 | data.save(thing);
36 | }
37 |
38 | @Cacheable(value = DEMO_CACHE_NAME, key = "#thing.getId()+'thing'")
39 | @Override
40 | public Thing findById(Long id) {
41 | System.err.println("没有走缓存!" + id);
42 | return data.findOne(id);
43 | }
44 |
45 | @Cacheable(value = DEMO_CACHE_NAME, key = THING_ALL_KEY)
46 | @Override
47 | public Iterable findAll() {
48 | return data.findAll();
49 | }
50 |
51 | //@Cacheable(value = DEMO_CACHE_NAME, key = THING_ALL_KEY)
52 | @Override
53 | public Iterable findByTitle(String title) {
54 | return data.findByTitle(title);
55 | }
56 |
57 | @Override
58 | @CachePut(value = DEMO_CACHE_NAME, key = "#thing.getId()+'thing'")
59 | @CacheEvict(value = DEMO_CACHE_NAME, key = THING_ALL_KEY)
60 | public Thing update(Thing thing) {
61 | System.out.println(thing);
62 | data.save(thing);
63 |
64 | return thing;
65 | }
66 |
67 | @CacheEvict(value = DEMO_CACHE_NAME,key = THING_ALL_KEY )
68 | @Override
69 | public void delete(Long id) {
70 | data.delete(id);
71 |
72 | }
73 |
74 | public Page findByPage(Pageable pageable){
75 | return data.findAll(pageable);
76 | }
77 |
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | #spring data source config
2 | spring.datasource.url=jdbc:mysql://localhost:3306/test
3 | spring.datasource.username=root
4 | spring.datasource.password=admin
5 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
6 |
7 | spring.datasource.initialsize=10
8 | # Number of ms to wait before throwing an exception if no connection is available.
9 | spring.datasource.max-wait=10
10 | # Maximum number of active connections that can be allocated from this pool at the same time.
11 | spring.datasource.max-active=50
12 | # Validate the connection before borrowing it from the pool.
13 | spring.datasource.test-on-borrow=true
14 |
15 | # Specify the DBMS
16 | spring.jpa.database = MYSQL
17 | spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
18 | # Show or not log for each sql query
19 | spring.jpa.show-sql = true
20 | # Hibernate ddl auto (create, create-drop, update)
21 | spring.jpa.hibernate.ddl-auto = update
22 | # Naming strategy
23 | spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
24 | # stripped before adding them to the entity manager)
25 | spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect
26 |
27 |
28 | # REDIS (RedisProperties)
29 | #spring.redis.database=
30 | spring.redis.host=
31 | spring.redis.password=
32 | spring.redis.port=6379
33 | spring.redis.pool.max-idle=100
34 | spring.redis.pool.min-idle=1
35 | spring.redis.pool.max-active=1000
36 | spring.redis.pool.max-wait=-1
37 | # name of Redis server
38 | #spring.redis.sentinel.master=
39 | # comma-separated list of host:port pairs
40 | #spring.redis.sentinel.nodes= localhost:6379
41 | #spring.data.mongodb.uri=mongodb://test:test@localhost:27017/test
42 | #web servlet config
43 | server.port=8088
44 |
45 | #logging
46 | #currently we use sl4j,Sentry is a better choice,if we want to realtime log
47 | #TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
48 | logging.level.org.springframework.web=DEBUG
49 | logging.level.org.hibernate=ERROR
50 | logging.path=d:/logs
51 | logging.file=bootdemo.log
52 | #logging.config= # location of config file (default classpath:logback.xml for logback)
53 | #endpoints
54 | #endpoints.sensitive=true
55 | #endpoints.info.sensitive=false
56 |
57 | info.build.artifact=springbootdemo
58 | info.build.name=springboot
59 | info.build.description=springboot description
60 | info.build.version=version-1.3
61 |
62 |
--------------------------------------------------------------------------------
/src/test/java/com/jvmhub/springboot/SpringBootThymeleafApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.ArrayList;
5 | import java.util.Date;
6 | import java.util.List;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import org.springframework.test.context.web.WebAppConfiguration;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.boot.test.SpringApplicationConfiguration;
13 | import org.springframework.data.domain.Page;
14 | import org.springframework.data.domain.PageRequest;
15 | import org.springframework.data.domain.Pageable;
16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17 |
18 | import com.jvmhub.springboot.domain.Thing;
19 | import com.jvmhub.springboot.repository.ThingRepository;
20 |
21 | import static org.junit.Assert.*;
22 |
23 | @RunWith(SpringJUnit4ClassRunner.class)
24 | @SpringApplicationConfiguration(classes = SpringBootThymeleafApplication.class)
25 | @WebAppConfiguration
26 | public class SpringBootThymeleafApplicationTests {
27 |
28 | @Autowired
29 | ThingRepository thingrepo;
30 |
31 | @Test
32 | public void contextLoads() {
33 | System.out.println(thingrepo.count());
34 | /*
35 | List vals = thingrepo.findByContentLike("abcd");
36 | assertEquals(vals.size(),0);
37 |
38 | List vals2 = thingrepo.findByContentLike("%123456789%");
39 | assertNotEquals(vals2.size(),0);
40 |
41 | List vals3 = thingrepo.findByDatefieldGreaterThan(new Date("2016/06/03 00:00:00"));
42 | assertNotEquals(vals3.size(),0);
43 |
44 | List vals4 = thingrepo.findByDatefieldBetween(new Date("2016/06/03 00:00:00"),new Date("2016/06/05 00:00:00"));
45 | assertNotEquals(vals4.size(),0);
46 |
47 | Page tmppage1 = thingrepo.findPartFields(new PageRequest(0,1));
48 | assertNotEquals(tmppage1.getContent().size(),0);
49 | */
50 | Thing tmpthing = new Thing("a1234","a1012345678901234567890123456789");
51 | tmpthing.setPhone("32432432432");
52 | tmpthing.setMoney(new BigDecimal("2"));
53 | thingrepo.save(tmpthing);
54 | //批量保存测试
55 | List tmpthinglist = new ArrayList();
56 | tmpthinglist.add(new Thing("new1_4","newcontent1_012345678901234567890123456789"));
57 | tmpthinglist.add(new Thing("new2_4","newcontent2_012345678901234567890123456789"));
58 | Listtmpresultlist = thingrepo.save(tmpthinglist);
59 | assertNotEquals(tmpresultlist.size(),0);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/jvmhub/springboot/redis/RedisConfig.java:
--------------------------------------------------------------------------------
1 | package com.jvmhub.springboot.redis;
2 |
3 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
4 | import com.fasterxml.jackson.annotation.PropertyAccessor;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 |
7 | import org.springframework.cache.CacheManager;
8 | import org.springframework.cache.annotation.CachingConfigurerSupport;
9 | import org.springframework.cache.annotation.EnableCaching;
10 | import org.springframework.cache.interceptor.KeyGenerator;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Configuration;
13 | import org.springframework.data.redis.cache.RedisCacheManager;
14 | import org.springframework.data.redis.connection.RedisConnectionFactory;
15 | import org.springframework.data.redis.core.RedisTemplate;
16 | import org.springframework.data.redis.core.StringRedisTemplate;
17 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
18 |
19 | import java.lang.reflect.Method;
20 |
21 |
22 | @Configuration
23 | @EnableCaching
24 | public class RedisConfig extends CachingConfigurerSupport{
25 |
26 | @Bean
27 | public KeyGenerator wiselyKeyGenerator(){
28 | return new KeyGenerator() {
29 | @Override
30 | public Object generate(Object target, Method method, Object... params) {
31 | StringBuilder sb = new StringBuilder();
32 | sb.append(target.getClass().getName());
33 | sb.append(method.getName());
34 | for (Object obj : params) {
35 | sb.append(obj.toString());
36 | }
37 | return sb.toString();
38 | }
39 | };
40 |
41 | }
42 |
43 | @Bean
44 | public CacheManager cacheManager(
45 | @SuppressWarnings("rawtypes") RedisTemplate redisTemplate) {
46 | return new RedisCacheManager(redisTemplate);
47 | }
48 |
49 | @Bean
50 | public RedisTemplate redisTemplate(
51 | RedisConnectionFactory factory) {
52 | StringRedisTemplate template = new StringRedisTemplate(factory);
53 | Jackson2JsonRedisSerializer