三种种方式:
对象形式
SQL语句形式 1
SQL语句形式2
对象形式
<pre name="code" class="java">@Query("select t from GoodsVipPrice t where t.goodsId in ?1 and t.vipLevel = ?2")
List<GoodsVipPrice> getGoodsVipPriceList(List<Long> goodsIdsList, int vipLevel);
@Modifying
@Query(value="delete from CourseCont cc where cc.courseId = ?1")
public void deleteCourseContByCourseId(long courseId);
@Modifying
@Query(value="update CourseCont cc set cc.status=1 where cc.courseId = ?1")
public void updateCourseContStatus(long courseId);
SQL语句形式 1
@Query(value="SELECT vce.* FROM virtual_currecy_exchange vce,virtual_currecy_info vci WHERE vce.CURRECY_ID=vci.ID AND vce.CODE=?1 AND vci.END_TIME>NOW()",nativeQuery=true)
public List<VirtualCurrecyExchange> findVirtualCurrecyExchangeByCode(String code);
@Modifying
@Query(value="update homework_info set status=1 where id in(select homework_id from video_homework where video_id in(select video_id from course_video where course_id=?1))",nativeQuery=true)
void updateHomeworkStatus(long courseId);
SQL语句形式2
@Resource(name = "onlinePagedJdbcTemplate")
private PagedJdbcTemplate onlinePagedJdbcTemplate;
public int queryCourseCatetoryIsUsed(long courseCatetoryId){
String sql = "select count(1) from dual where exists(select 1 from goods_info where shop_category_id = ?) or (exists(select 1 from course_info where shop_category_id = ?))";
return onlinePagedJdbcTemplate.queryForInt(sql,courseCatetoryId,courseCatetoryId);
}
/**
* 级联删除课程分类byId
* @param id
*/
public void cascadeDeleteCategory(long id){
String sql = "delete from shop_course_category where id = ? or pid = ?";
onlinePagedJdbcTemplate.update(sql,id,id);
}
public List<UserInfo> getValidEmailList(String email){
String sql = "SELECT * FROM user_info WHERE STATUS<2 AND email=? ";
return onlinePagedJdbcTemplate.query(sql, new Object[]{email}, BeanPropertyRowMapper.newInstance(UserInfo.class));
}