Search in sources :

Example 6 with Person

use of com.xiaolyuh.entity.Person in project spring-boot-student by wyh-spring-ecosystem-student.

the class PersonServiceImpl method findOne.

/**
 * LayCacheable
 * value:缓存key的前缀。
 * key:缓存key的后缀。
 * sync:设置如果缓存过期是不是只放一个请求去请求数据库,其他请求阻塞,默认是false。
 */
@Override
@Cacheable(value = "people")
public Person findOne() {
    Person p = personRepository.findOne(2L);
    logger.info("为id、key为:" + p.getId() + "数据做了缓存");
    return p;
}
Also used : Person(com.xiaolyuh.entity.Person) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 7 with Person

use of com.xiaolyuh.entity.Person in project spring-boot-student by wyh-spring-ecosystem-student.

the class PersonServiceImpl method findOne1.

@Override
// 3
@Cacheable(value = "people#120#120")
public Person findOne1() {
    Person p = personRepository.findOne(2L);
    System.out.println("为id、key为:" + p.getId() + "数据做了缓存");
    return p;
}
Also used : Person(com.xiaolyuh.entity.Person) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 8 with Person

use of com.xiaolyuh.entity.Person in project spring-boot-student by wyh-spring-ecosystem-student.

the class PersonServiceImpl method findOne2.

@Override
// 3
@Cacheable(value = "people2")
public Person findOne2(Person person) {
    Person p = personRepository.findOne(person.getId());
    System.out.println("为id、key为:" + p.getId() + "数据做了缓存");
    return p;
}
Also used : Person(com.xiaolyuh.entity.Person) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 9 with Person

use of com.xiaolyuh.entity.Person in project spring-boot-student by wyh-spring-ecosystem-student.

the class SpringBootStudentCacheRedisApplicationTests method testParse.

@Test
public void testParse() {
    Person p = new Person();
    p.setId(11L);
    p.setAge(32);
    // 表达式解析
    ExpressionParser expressionParser = new SpelExpressionParser();
    Expression expression = expressionParser.parseExpression("#person.age+\":\"+#person.id");
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setRootObject(p);
    logger.info("[SpELTest - testParse ] {} ", expression.getValue(context));
    Field[] fields = p.getClass().getDeclaredFields();
    for (Field field : fields) {
        try {
            System.out.println("name:" + field.getName());
            field.setAccessible(true);
            System.out.println("value:" + field.get(p));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : Field(java.lang.reflect.Field) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Person(com.xiaolyuh.entity.Person) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Person

use of com.xiaolyuh.entity.Person in project spring-boot-student by wyh-spring-ecosystem-student.

the class PersonService method save.

/**
 * 保存
 * @param person
 * @return
 */
@Transactional
public Person save(Person person) {
    // 获取配置的数据源
    DataSource dataSource = applicationContext.getBean(DataSource.class);
    // 查看配置数据源信息
    System.out.println(dataSource);
    System.out.println(dataSource.getClass().getName());
    System.out.println(dataSourceProperties);
    Person p = personRepository.save(person);
    return p;
}
Also used : Person(com.xiaolyuh.entity.Person) DataSource(javax.sql.DataSource) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Person (com.xiaolyuh.entity.Person)21 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Expression (org.springframework.expression.Expression)6 ExpressionParser (org.springframework.expression.ExpressionParser)6 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)6 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)6 Cacheable (org.springframework.cache.annotation.Cacheable)5 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Transactional (org.springframework.transaction.annotation.Transactional)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SentinelResource (com.alibaba.csp.sentinel.annotation.SentinelResource)1 Location (com.xiaolyuh.entity.Location)1 CsvExportUtil (com.xiaolyuh.utils.CsvExportUtil)1 ExcelExportUtils (com.xiaolyuh.utils.ExcelExportUtils)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1