在mybatis里面各种符号的使用
< <= > >= & ' "
< <= > >= & ' "
查询自增主键
这是给没有自增的数据库使用的
select LAST_INSERT_ID()
通过uuid来查询主键
oracle自增序列来查询
${}和#{}的区别
综合查询
使用包装对象查询
一般在筛选的时候可以用
输入条件循环
ids是对象的一个属性
奇怪的报错1
前端报错415
"timestamp": "2019-08-12T08:54:17.113+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/octet-stream' not supported",
"path": "/api/patrol/grid/grid-chief"
原因是Content-Type上面有一个奇怪的空格
put http://localhost:8080/api/patrol/grid/grid-chief
Content-Type: application/json
{
"id": 2,
"name": "网格员11",
"gridId": 7,
"state": "LEAVE"
}
奇怪的报错2
keyProperty' must include the parameter name (e.g. 'param.id'). Specified key properties are [id] and available parameters are [patrolPlan, gridId, param1, param2]] with root cause
我的mapper
void insertPatrolPlan(@Param("gridId") int gridId, @Param("patrolPlan") PatrolPlan patrolPlan);
这是因为mybatis写错了
<!--新增计划-->
<insert id="insertPatrolPlan" useGeneratedKeys="true" keyProperty="id">
insert into patrol_patrol_plan (
grid_id
) values (
#{patrolPlan.gridId}
)
</insert>
不知道id是什么
修改后
<!--新增计划-->
<insert id="insertPatrolPlan" useGeneratedKeys="true" keyProperty="patrolPlan.id">
insert into patrol_patrol_plan (
grid_id
) values (
#{patrolPlan.gridId}
)
</insert>
如果只传patrolPlan 就不用写patrolPlan.id,否则就需要
where的用法
<select id="findAllDroneStationLog" resultType="com.swcote.patrol.entity.PatrolDroneStationLog">
select
id,
station_id as "stationId",
plan_id AS "planId",
attachment_flight_air_id AS "attachmentFlightAirId",
start_time AS "startTime",
end_time AS "endTime",
state
from patrol_drone_station_log
<where>
<if test="startTime != null ">
and start_time >= #{startTime}
</if>
<if test="endTime != null ">
and #{endTime} >= end_time
</if>
</where>
order by id desc
</select>