代码拉取完成,页面将自动刷新
本插件实现类似Spring data jpa功能,通过方法名动态生成SQL进行查询,提升开发效率
<bean id="myBatisSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ods-osp-stateDataSource" />
<property name="mapperLocations" >
<list>
<value>classpath*:mapper/*Mapper.xml</value>
</list>
</property>
<!-- 配置Mybatis的插件plugin-->
<property name="plugins">
<array>
<bean id="jpaInterceptor" class="com.mybatis.jpa.interceptor.JpaInterceptor"></bean>
</array>
</property>
</bean>
//没有使用@Table,类名转化成表名,由驼峰转成下划线写法,例如:JobStateIndex --> job_state_index
//使用@Table注解就以name的值对应数据库的表名
@Table(name="job_state_index")
public class JobStateIndex {
@Id //主键,必须定义,否则报异常
private Long id;
@Column(name="index_num") //字段名,功能和@Table方法一样
private String orderSn;
// 没有使用@Column,属性名转成数据库字段名
private Integer indexNum;
private Date createTime;
}
public interface CrudRepository<T> {
// 提供批量insert方法,保存后主键回写对象有@Id注解的属性上
@Insert("")
@Options(useGeneratedKeys = true)
void saveAll(List<T> list);
}
// 必须继承CrudRepository接口
public interface SelectRepository extends CrudRepository<JobStateIndex> {
@Select("") // 必填
@ResultMap("AutoMapperResultMap") // 对应定义resultMap,通常在XML已经定义
@Options( flushCache = true) // 关闭一级缓存,解决在同一个session里多次调用只返回第一次查询的结果
List<JobStateIndex> findByOrderSn(String orderSn);
@Select("")
@ResultMap("AutoMapperResultMap")
List<JobStateIndex> findByIdIn(List<Integer> ids);
@Select("")
@ResultMap("AutoMapperResultMap")
List<JobStateIndex> findByIdInAndIndexNum(List<Integer> ids, int indexNum);
}
keyword | Sample | 说明 |
---|---|---|
findBy | findByOrderSn | 声明使用select sql |
And | findByIdInAndIndexNum | where x.id = ? and x.index_num = ? |
Equals | findById, findByIdEquals | where x.id = ? |
LessThan | findByLessThan | where x.id < ? |
LessThanEqual | findByIdLessThanEqual | where x.id <= ? |
GreaterThan | findByIdGreaterThan | where x.id > ? |
GreaterThanEqual | findByIdGreaterThanEqual | where x.id >= ? |
In | findByIdIn(List ids) | where x.id in (?) |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。