/**
* HQL通过旅店名称查询旅店以及城市的所有信息
*
* @return
*/
@Query(value = "select new map(t1,t2) from TCity t1 left join THotel t2 on t1.id=t2.city where t2.name =:name")
List
测试方法和2是差不多的 我就不粘贴了
Map 转换实体类的方法也挺多的我就不多说了,如果是直接返回给前台的话,也没有必要转换成对象.
4.HQL通过旅店名称查询旅店以及城市的所有信息 直接返回实体类
/**
* 关联查询
*
* @return
*/
@Query(value = "select new pers.zpw.domain.CityHohel(t1.name AS cityName,t2.name AS hotelName) from TCity t1 left join THotel t2 on t1.id=t2.city where t2.name =:name")
List findCityAndHotelByHQLResultObj(@Param("name") String name);
为了方便CityHohel我只封装了2个属性,这和HQL查询的字段是完全一致的,也必须要保持一致.
/**
* Created by ZhuPengWei on 2018/5/12.
*/
@Data
public class CityHohel {
private String cityName;
private String hotelName;
public CityHohel(String cityName, String hotelName) {
this.cityName = cityName;
this.hotelName = hotelName;
}
}
当然这个带参的构造方法是必须要写的,否则会抛出转换实体的异常
单元测试
@Test
public void findCityAndHotelByHQLResultObj() throws Exception {
List cityAndHotelByHQLResultObj = tCityRepository.findCityAndHotelByHQLResultObj("酒店");
Assert.assertTrue(cityAndHotelByHQLResultObj.size() > 0);
}
4.HQL通过旅店名称分页查询旅店以及城市的所有信息 直接返回实体类
/**
* 关联查询
*
* @return
*/
@Query(value = "select new pers.zpw.domain.CityHohel(t1.name AS cityName,t2.name AS hotelName) from TCity t1 left join THotel t2 on t1.id=t2.city where t2.name =:name",
countQuery = "select count(*) from TCity t1 left join THotel t2 on t1.id=t2.city where t2.name =:name")
Page findCityAndHotelAllSelf(@Param("name") String name, Pageable pageable);
@Test
public void findCityAndHotelAllSelf() throws Exception {
Page cityAndHotelAllSelf = tCityRepository.findCityAndHotelAllSelf("酒店", new PageRequest(0, 10));
Assert.assertTrue(cityAndHotelAllSelf.getTotalElements() > 0);
}
在数据库系统中存储过程是必不可少的利器,存储过程是预先编译好的为实现一个复杂功能的一段Sql语句集合。它的优点我就不多说了,说一下我碰到的问题吧。我在项目开发的过程中需要用存储过程来实现一个功能,其中涉及到判断一张表是否已经建立,没有建立就由存储过程来建立这张表。
CREATE OR REPLACE PROCEDURE TestProc
IS
fla
使用jsonp不能发起POST请求。
It is not possible to make a JSONP POST request.
JSONP works by creating a <script> tag that executes Javascript from a different domain; it is not pos
(一)Keepalived
(1)安装
# cd /usr/local/src
# wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
# tar zxvf keepalived-1.2.15.tar.gz
# cd keepalived-1.2.15
# ./configure
# make &a