Spring Boot 实践 第六章 Spring data JAP在实际开发中的封装和应用(上)_jparepositoryfactorybean封装-程序员宅基地

技术标签: spring boot  spring data jpa  

上一章简单介绍了一下Spring boot和Spring Data JPA的整合和简单使用.  但是在实际开发过程中, 我们发现Spring Data JPA提供的接口太简单了,这样就导致需要编写大量的重复代码. 实际上Spring Data JPA提供了很多种扩展方式. 下面就介绍其中的一种.在上一章的代码基础上,做一些修改,我们会发现在Spring boot 中使用Spring Data JPA 更容易一些.

由于篇幅的问题,本章分两部分


 1.首先,需要建立一个所有Domain的基类, 这个基类可以什么都不写,也可以写一些基础的字段比如下面的例子

@Data
@MappedSuperclass
public abstract class TableEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Long id;

    /** 创建时间 */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false, updatable = false)
    protected Date createTime;

    /** 最后更新时间 */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(insertable = false)
    protected Date lastModifyTime;

    /** 版本号,用于实现乐观锁 */
    @Version
    @Column(name = "version", nullable = false)
    protected int version;

    @PrePersist
    @PreUpdate
    protected void updateDate(){
        if(createTime==null){
            createTime = new Date();
        }
        lastModifyTime = new Date();
    }
}

这个domain的抽象类描述了四个字段, 分别是ID, 记录创建时间, 最后更新时间, 和实现乐观锁的版本号.这都是ORM中常用的字段, 并且这些字段实现了自动更新. 

2. 回忆一下上一章, 我们的Repository是继承了JpaRepository, 我们现在需要自己扩展JpaRepository. 先写一个扩展接口,让它继承JpaRepository

@NoRepositoryBean
public interface BaseJpaRepository<T extends TableEntity, ID extends Serializable> extends JpaRepository<T, ID> {
}

3.这个接口中先什么都不实现, 接着再写一个它的实现

@NoRepositoryBean
@Transactional(readOnly = true)
public class SimpleBaseJpaRepository<T extends TableEntity, ID extends Serializable>
        extends SimpleJpaRepository<T, ID> implements
        BaseJpaRepository<T, ID>  {
}

 注意: 上面这两个类头上的@NoRepositoryBean注解标明这不是一个Repository的bean, 不需要spring 来自动实现Impl子类

 4.扩展工厂类

仅仅有上面这个扩展接口和扩展实现是不能完成对Spring Data JPA 扩展的. 我们注意到上一章我们只是写了一个 Repository的接口并继承了JpaRepository, 并没有写实现类. 注入这个接口就可以使用它的方法来.  实际上Spring Data JPA依据继承的JpaRepository, 用工厂自动填补了一个子类的. 那么我们虽然扩展了JpaRepository, 但是没有扩展Spring Data JPA的工厂方法,就还是完成扩展. 接下来我们开始扩展工厂类:

public class BaseJpaRepositoryFactory extends JpaRepositoryFactory {
    public BaseJpaRepositoryFactory(EntityManager entityManager) {
        super(entityManager);
    }

    @Override
    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
        return SimpleBaseJpaRepository.class;
    }
}

 注意: 这个类继承了JpaRepositoryFactory, 也就是JpaRepository的工厂类, 并且覆盖了getRepositoryBaseClass的方法,让它返回我们扩展的SimpleBaseJpaRepository.

5.创建JpaRepositoryFactory的Factory

有了扩展工厂类后,还需要有一个创建JpaRepositoryFactory的Factory, 代码示例如下:

public class BaseJpaRepositoryFactoryBean<R extends JpaRepository<T, ID>, T extends TableEntity, ID extends Serializable>
        extends JpaRepositoryFactoryBean<R, T, ID> {

    public BaseJpaRepositoryFactoryBean(Class<? extends R> repositoryInterface) {
        super(repositoryInterface);
    }

    protected RepositoryFactorySupport createRepositoryFactory(
            EntityManager entityManager) {
        return new BaseJpaRepositoryFactory(entityManager);
    }
}

6.创建RepositoryConfig

到这里,对Spring Data JPA的扩展框架已经搭好了, 在给BaseJpaRepository和SimpleBaseJpaRepository填写扩展方法之前,我们需要对上个例子中的RepositoryConfig进行一下修改. 找到RepositoryConfig这个类, 将@EnableJpaRepositories注解中的repositoryFactoryBeanClass修改为我们自己的工厂的工厂类 BaseJpaRepositoryFactoryBean.class 代码如下:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        basePackages = {"org.learning.repository"},
        repositoryFactoryBeanClass = BaseJpaRepositoryFactoryBean.class)
public class RepositoryConfig {
private static final String HIBERNATE_DIALECT = "hibernate.dialect";
    private static final String HIBERNATE_SHOW_SQL = "hibernate.show.sql";
    private static final String HIBERNATE_HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";
    private static final String HIBERNATE_EJB_NAMING_STRATEGY = "hibernate.ejb.naming_strategy";

    @Autowired
    private DataSource dataSource;

    @Value("${spring.jpa.show-sql}")
    private String showSql;

    @Value("${spring.jpa.generate-ddl}")
    private String generateDdl;

    @Value("${spring.jpa.hibernate.ddl-auto}")
    private String hibernateDdl;

    @Value("${spring.jpa.database-platform}")
    private String databasePlatform;

    @Bean
    public LocalContainerEntityManagerFactoryBean  entityManagerFactory() {
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setDataSource(dataSource);
        factory.setPackagesToScan("org.learning.entity");

        Map<String, Object> jpaProperties = new HashMap<>();
        jpaProperties.put(HIBERNATE_SHOW_SQL, showSql);
        jpaProperties.put(HIBERNATE_DIALECT, databasePlatform);
        jpaProperties.put(HIBERNATE_HBM2DDL_AUTO, hibernateDdl);
        jpaProperties.put(HIBERNATE_EJB_NAMING_STRATEGY, "org.hibernate.cfg.ImprovedNamingStrategy");

        factory.setJpaPropertyMap(jpaProperties);
        factory.afterPropertiesSet();
        return factory;
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory().getObject());
        return txManager;
    }
}

 

7.开始填写扩展方法, 首先需要给SimpleBaseJpaRepository创建一个构造函数,代码如下:

@NoRepositoryBean
@Transactional(readOnly = true)
public class SimpleBaseJpaRepository<T extends TableEntity, ID extends Serializable>
        extends SimpleJpaRepository<T, ID> implements
        BaseJpaRepository<T, ID>  {

    protected EntityManager entityManager;

    private final JpaEntityInformation<T, ?> entityInformation;

    protected Class<T> domainClass;

    /**
     * 父类的构造函数
     *
     * @param entityInformation
     * @param entityManager
     */
    public SimpleBaseJpaRepository(
            JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
        super(entityInformation, entityManager);
        this.entityManager = entityManager;
        this.entityInformation = entityInformation;
        this.domainClass = entityInformation.getJavaType();

    }
}

在构造函数中需要调用父类的构造函数把EntityManager和JpaEntityInformation初始化了.

8.自定义一个动态查询器 

Spring Data JPA没有提供类似Hibernate中Criteria的动态查询器,但是往往项目中有很多动态查询.那就封装一个吧. 下面是代码示例:

Criterion接口:

public interface Criterion {
    /**
     * 操作符
     */
    enum Operator {
        EQ, NE, LIKE, GT, LT, GTE, LTE, AND, OR, ISNULL, ISNOTNULL, LEFTLIKE, RIGHTLIKE, BETWEEN, IN
    }

    Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder);

}

Criteria查询器, 继承Specification:

public class Criteria<T> implements Specification<T> {

    private List<Criterion> criterions = new ArrayList<Criterion>();


    public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
        if (!criterions.isEmpty()) {
            List<Predicate> predicates = new ArrayList<Predicate>();
            for(Criterion c : criterions){
                predicates.add(c.toPredicate(root, query, builder));
            }
            // 将所有条件用 and 联合起来
            if (predicates.size() > 0) {
                return builder.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        }
        return builder.conjunction();
    }

    /**
     * 增加简单条件表达式
     * @param criterion
     */
    public void add(Criterion criterion){
        if(criterion!=null){
            criterions.add(criterion);
        }
    }



    private boolean isField(Field[] fields, String queryKey) {
        if (fields == null || fields.length == 0) {
            return false;
        }
        for (Field field : fields) {
            if (field.getName().equals(queryKey)) {
                return true;
            }
        }
        return false;
    }
}

再建几个表达式类

public class SimpleExpression implements Criterion {
    private String fieldName;       //属性名
    private Object value;           //对应值
    private Object[] values;           //对应值
    private Operator operator;      //计算符

    protected SimpleExpression(String fieldName, Object value, Operator operator) {
        this.fieldName = fieldName;
        this.value = value;
        this.operator = operator;
    }


    protected SimpleExpression(String fieldName, Operator operator) {
        this.fieldName = fieldName;
        this.operator = operator;
    }

    protected SimpleExpression(String fieldName, Operator operator, Object... values) {
        this.fieldName = fieldName;
        this.values = values;
        this.operator = operator;
    }

    public String getFieldName() {
        return fieldName;
    }
    public Object getValue() {
        return value;
    }
    public Operator getOperator() {
        return operator;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,
                                 CriteriaBuilder builder) {
        Path expression ;
        if(fieldName.contains(".")){
            String[] names = StringUtils.split(fieldName, ".");
            expression = root.get(names[0]);
            for (int i = 1; i < names.length; i++) {
                expression = expression.get(names[i]);
            }
        }else{
            expression = root.get(fieldName);
        }

        switch (operator) {
            case EQ:
                return builder.equal(expression, value);
            case NE:
                return builder.notEqual(expression, value);
            case LIKE:
                return builder.like((Expression<String>) expression, "%" + value + "%");
            case LEFTLIKE:
                return builder.like((Expression<String>) expression, "%" + value);
            case RIGHTLIKE:
                return builder.like((Expression<String>) expression, value + "%");
            case LT:
                return builder.lessThan(expression, (Comparable) value);
            case GT:
                return builder.greaterThan(expression, (Comparable) value);
            case LTE:
                return builder.lessThanOrEqualTo(expression, (Comparable) value);
            case GTE:
                return builder.greaterThanOrEqualTo(expression, (Comparable) value);
            case ISNULL:
                return builder.isNull(expression);
            case ISNOTNULL:
                return builder.isNotNull(expression);
            case IN:
                return ((CriteriaBuilderImpl)builder).in(expression, values);
            default:
                return null;
        }
    }
}
public class LogicalExpression implements Criterion {

    private Criterion[] criterion;  // 逻辑表达式中包含的表达式
    private Operator operator;      //计算符

    LogicalExpression(Criterion[] criterions, Operator operator) {
        this.criterion = criterions;
        this.operator = operator;
    }

    @Override
    public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,
                                 CriteriaBuilder builder) {
        List<Predicate> predicates = new ArrayList<Predicate>();
        for (Criterion aCriterion : this.criterion) {
            predicates.add(aCriterion.toPredicate(root, query, builder));
        }
        switch (operator) {
            case OR:
                return builder.or(predicates.toArray(new Predicate[predicates.size()]));
            default:
                return builder.and(predicates.toArray(new Predicate[predicates.size()]));
        }
    }
}
public class BetweenExpression implements Criterion {

    private final String fieldName;
    private Object lo;
    private Object hi;


    BetweenExpression(String fieldName, Object lo, Object hi) {
        this.fieldName = fieldName;
        this.lo = lo;
        this.hi = hi;

    }


    @Override
    public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
        Path expression ;
        if(fieldName.contains(".")){
            String[] names = StringUtils.split(fieldName, ".");
            expression = root.get(names[0]);
            for (int i = 1; i < names.length; i++) {
                expression = expression.get(names[i]);
            }
        }else{
            expression = root.get(fieldName);
        }


        if (lo instanceof Date && hi instanceof Date) {
            return builder.between(expression, (Date)lo, (Date)hi);
        } else if (lo instanceof String && hi instanceof String) {
            return builder.between(expression, (String)lo, (String)hi);
        } else if (lo instanceof Integer && hi instanceof Integer) {
            return builder.between(expression, (Integer)lo, (Integer)hi);
        } else if (lo instanceof Double && hi instanceof Double) {
            return builder.between(expression, (Double)lo, (Double)hi);
        } else if (lo instanceof BigDecimal && hi instanceof BigDecimal) {
            return builder.between(expression, (BigDecimal)lo, (BigDecimal)hi);
        } else {
            return null;
        }
    }
}
public class ColumnExpression implements Criterion {

    private final String fieldNameA;

    private final String fieldNameB;

    private Operator operator;      //计算符


    ColumnExpression(String fieldNameA, String fieldNameB, Operator operator) {
        this.fieldNameA = fieldNameA;
        this.fieldNameB = fieldNameB;
        this.operator = operator;
    }



    @Override
    public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
        Path expressionA ;
        if(fieldNameA.contains(".")){
            String[] names = StringUtils.split(fieldNameA, ".");
            expressionA = root.get(names[0]);
            for (int i = 1; i < names.length; i++) {
                expressionA = expressionA.get(names[i]);
            }
        }else{
            expressionA = root.get(fieldNameA);
        }

        Path expressionB ;
        if(fieldNameB.contains(".")){
            String[] names = StringUtils.split(fieldNameB, ".");
            expressionB = root.get(names[0]);
            for (int i = 1; i < names.length; i++) {
                expressionB = expressionB.get(names[i]);
            }
        }else{
            expressionB = root.get(fieldNameB);
        }
        switch (operator) {
            case EQ:
                return builder.equal(expressionA, expressionB);
            case NE:
                return builder.notEqual(expressionA, expressionB);
            default:
                return null;
        }
    }
}

最后是条件比较器Restrictions:

public class Restrictions {
    /**
     * 等于
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression eq(String fieldName, Object value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.EQ);
    }

    /**
     * 不等于
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression ne(String fieldName, Object value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.NE);
    }

    /**
     * 模糊匹配
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression like(String fieldName, String value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.LIKE);
    }

    /**
     * 模糊匹配
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression leftLike(String fieldName, String value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.LEFTLIKE);
    }

    /**
     * 模糊匹配
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression rightLike(String fieldName, String value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.RIGHTLIKE);
    }



    /**
     * 大于
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression gt(String fieldName, Object value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.GT);
    }

    /**
     * 小于
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression lt(String fieldName, Object value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.LT);
    }

    /**
     * 大于等于
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression gte(String fieldName, Object value) {
        if(value == null) {
            return null;
        }
        return new SimpleExpression (fieldName, value, Criterion.Operator.GTE);
    }

    /**
     * 小于等于
     * @param fieldName
     * @param value
     * @return
     */
    public static SimpleExpression lte(String fieldName, Object value) {
        if(value == null) {
            return null;
        }

        return new SimpleExpression (fieldName, value, Criterion.Operator.LTE);
    }

    /**
     * 并且
     * @param criterions
     * @return
     */
    public static LogicalExpression and(Criterion... criterions){
        return new LogicalExpression(criterions, Criterion.Operator.AND);
    }
    /**
     * 或者
     * @param criterions
     * @return
     */
    public static LogicalExpression or(Criterion... criterions){
        return new LogicalExpression(criterions, Criterion.Operator.OR);
    }


    /**
     * 包含于
     * @param fieldName
     * @param value
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static SimpleExpression in(String fieldName, Collection value) {
        return new SimpleExpression(fieldName, Criterion.Operator.IN, value.toArray());
    }


    /**
     * 不包含于
     * @param fieldName
     * @param value
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static LogicalExpression notIn(String fieldName, Collection value) {
        if((value==null||value.isEmpty())){
            return null;
        }
        SimpleExpression[] ses = new SimpleExpression[value.size()];
        int i=0;
        for(Object obj : value){
            ses[i]=new SimpleExpression(fieldName,obj, Criterion.Operator.NE);
            i++;
        }
        return new LogicalExpression(ses, Criterion.Operator.AND);
    }

    /**
     * 列为空
     * @param fieldName
     * @return
     */
    public static LogicalExpression isNull(String fieldName) {
        SimpleExpression[] ses = new SimpleExpression[1];
        ses[0] = new SimpleExpression(fieldName, Criterion.Operator.ISNULL);
        return new LogicalExpression(ses, Criterion.Operator.ISNULL);
    }

    /**
     * 列不为空
     * @param fieldName
     * @return
     */
    public static LogicalExpression isNotNull(String fieldName) {
        SimpleExpression[] ses = new SimpleExpression[1];
        ses[0] = new SimpleExpression(fieldName, Criterion.Operator.ISNOTNULL);
        return new LogicalExpression(ses, Criterion.Operator.ISNOTNULL);
    }



    /**
     * 时间范围
     * @param fieldName
     * @return
     */
    public static LogicalExpression between(String fieldName, Object startDate, Object endDate) {
        BetweenExpression[] bes = new BetweenExpression[1];
        bes[0] = new BetweenExpression(fieldName, startDate, endDate);
        return new LogicalExpression(bes, Criterion.Operator.BETWEEN);
    }

    /**
     * 等于
     * @param fieldNameA
     * @param fieldNameB
     * @return
     */
    public static ColumnExpression eqCol(String fieldNameA, String fieldNameB) {
        if(StringUtil.isBlank(fieldNameA) || StringUtil.isBlank(fieldNameB)) {
            return null;
        }
        return new ColumnExpression(fieldNameA, fieldNameB, Criterion.Operator.EQ);
    }

    /**
     * bu等于
     * @param fieldNameA
     * @param fieldNameB
     * @return
     */
    public static ColumnExpression neCol(String fieldNameA, String fieldNameB) {
        if(StringUtil.isBlank(fieldNameA) || StringUtil.isBlank(fieldNameB)) {
            return null;
        }
        return new ColumnExpression(fieldNameA, fieldNameB, Criterion.Operator.NE);
    }



    /**
     * 时间范围
     * @param fieldName
     * @return
     */
    public static LogicalExpression eqDate(String fieldName, Object date) {
        BetweenExpression[] bes = new BetweenExpression[1];

        Date startDate;
        Date endDate;
        try {
            if(date instanceof String){
                startDate = stringToDateTime(date.toString() + " 00:00:00");
                endDate = stringToDateTime(date.toString() + " 23:59:59");
            }else if(date instanceof Date){
                Calendar calendar = Calendar.getInstance();
                calendar.setTime((Date)date);
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND,0);

                startDate = calendar.getTime();

                calendar.set(Calendar.HOUR_OF_DAY,23);
                calendar.set(Calendar.MINUTE,59);
                calendar.set(Calendar.SECOND,59);

                endDate = calendar.getTime();
            }else{
                return null;
            }
        }catch (Exception ignored){
            return null;
        }

        bes[0] = new BetweenExpression(fieldName, startDate, endDate);
        return new LogicalExpression(bes, Criterion.Operator.BETWEEN);
    }


    private final static String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

    private static Date stringToDateTime(String dateString) {
        if (dateString == null) {
            return null;
        }
        try {

            DateFormat df = new SimpleDateFormat(DATETIME_PATTERN);
            df.setLenient(false);
            return df.parse(dateString);
        } catch (ParseException e) {
            return null;
        }
    }
}

本章结束 

本章介绍了jpa封装的部分代码, 下一章接着展示后面的代码

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jsf1983/article/details/83186628

智能推荐

前端开发之vue-grid-layout的使用和实例-程序员宅基地

文章浏览阅读1.1w次,点赞7次,收藏34次。vue-grid-layout的使用、实例、遇到的问题和解决方案_vue-grid-layout

Power Apps-上传附件控件_powerapps点击按钮上传附件-程序员宅基地

文章浏览阅读218次。然后连接一个数据源,就会在下面自动产生一个添加附件的组件。把这个控件复制粘贴到页面里,就可以单独使用来上传了。插入一个“编辑”窗体。_powerapps点击按钮上传附件

C++ 面向对象(Object-Oriented)的特征 & 构造函数& 析构函数_"object(cnofd[\"ofdrender\"])十条"-程序员宅基地

文章浏览阅读264次。(1) Abstraction (抽象)(2) Polymorphism (多态)(3) Inheritance (继承)(4) Encapsulation (封装)_"object(cnofd[\"ofdrender\"])十条"

修改node_modules源码,并保存,使用patch-package打补丁,git提交代码后,所有人可以用到修改后的_修改 node_modules-程序员宅基地

文章浏览阅读133次。删除node_modules,重新npm install看是否成功。在 package.json 文件中的 scripts 中加入。修改你的第三方库的bug等。然后目录会多出一个目录文件。_修改 node_modules

【】kali--password:su的 Authentication failure问题,&sudo passwd root输入密码时Sorry, try again._password: su: authentication failure-程序员宅基地

文章浏览阅读883次。【代码】【】kali--password:su的 Authentication failure问题,&sudo passwd root输入密码时Sorry, try again._password: su: authentication failure

整理5个优秀的微信小程序开源项目_微信小程序开源模板-程序员宅基地

文章浏览阅读1w次,点赞13次,收藏97次。整理5个优秀的微信小程序开源项目。收集了微信小程序开发过程中会使用到的资料、问题以及第三方组件库。_微信小程序开源模板

随便推点

Centos7最简搭建NFS服务器_centos7 搭建nfs server-程序员宅基地

文章浏览阅读128次。Centos7最简搭建NFS服务器_centos7 搭建nfs server

Springboot整合Mybatis-Plus使用总结(mybatis 坑补充)_mybaitis-plus ruledataobjectattributemapper' and '-程序员宅基地

文章浏览阅读1.2k次,点赞2次,收藏3次。前言mybatis在持久层框架中还是比较火的,一般项目都是基于ssm。虽然mybatis可以直接在xml中通过SQL语句操作数据库,很是灵活。但正其操作都要通过SQL语句进行,就必须写大量的xml文件,很是麻烦。mybatis-plus就很好的解决了这个问题。..._mybaitis-plus ruledataobjectattributemapper' and 'com.picc.rule.management.d

EECE 1080C / Programming for ECESummer 2022 Laboratory 4: Global Functions Practice_eece1080c-程序员宅基地

文章浏览阅读325次。EECE 1080C / Programming for ECESummer 2022Laboratory 4: Global Functions PracticePlagiarism will not be tolerated:Topics covered:function creation and call statements (emphasis on global functions)Objective:To practice program development b_eece1080c

洛谷p4777 【模板】扩展中国剩余定理-程序员宅基地

文章浏览阅读53次。被同机房早就1年前就学过的东西我现在才学,wtcl。设要求的数为\(x\)。设当前处理到第\(k\)个同余式,设\(M = LCM ^ {k - 1} _ {i - 1}\) ,前\(k - 1\)个的通解就是\(x + i * M\)。那么其实第\(k\)个来说,其实就是求一个\(y\)使得\(x + y * M ≡ a_k(mod b_k)\)转化一下就是\(y * M ...

android 退出应用没有走ondestory方法,[Android基础论]为何Activity退出之后,系统没有调用onDestroy方法?...-程序员宅基地

文章浏览阅读1.3k次。首先,问题是如何出现的?晚上复查代码,发现一个activity没有调用自己的ondestroy方法我表示非常的费解,于是我检查了下代码。发现再finish代码之后接了如下代码finish();System.exit(0);//这就是罪魁祸首为什么这样写会出现问题System.exit(0);////看一下函数的原型public static void exit (int code)//Added ..._android 手动杀死app,activity不执行ondestroy

SylixOS快问快答_select函数 导致堆栈溢出 sylixos-程序员宅基地

文章浏览阅读894次。Q: SylixOS 版权是什么形式, 是否分为<开发版税>和<运行时版税>.A: SylixOS 是开源并免费的操作系统, 支持 BSD/GPL 协议(GPL 版本暂未确定). 没有任何的运行时版税. 您可以用她来做任何 您喜欢做的项目. 也可以修改 SylixOS 的源代码, 不需要支付任何费用. 当然笔者希望您可以将使用 SylixOS 开发的项目 (不需要开源)或对 SylixOS 源码的修改及时告知笔者.需要指出: SylixOS 本身仅是笔者用来提升自己水平而开发的_select函数 导致堆栈溢出 sylixos

推荐文章

热门文章

相关标签