3、编写处理逻辑
ScheduleController.java
@Controllerpublic class ScheduleController {@Autowiredprivate ScheduleService service;@RequestMapping("schedule")@ResponseBodypublic List<ScheduleVo> selectByFilmId(String filmId){List<ScheduleVo> voList=service.selectByFilmId(filmId);return voList;}}
ScheduleVo.java
public class ScheduleVo {private String scheduleId;private String scheduleTime;private String lanType;private BigDecimal price;private String roomId;private String roomName;private String filmId;private String filmName;//...}
ScheduleService.java
@Servicepublic class ScheduleService {@Autowiredprivate ScheduleMapper scheduleMapper;public List<ScheduleVo> selectByFilmId(String filmId){List<Schedule> scheduleList=scheduleMapper.selectByFilmId(filmId);List<ScheduleVo> result = new ArrayList<>();for (Schedule schedule : scheduleList) {ScheduleVo vo = new ScheduleVo();vo.setFilmId(schedule.getFilmId());vo.setFilmName(schedule.getFilmName());vo.setRoomId(schedule.getRoomId());vo.setRoomName(schedule.getRoomName());SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String dateStr = format.format(schedule.getScheduleTime());vo.setScheduleTime(dateStr);vo.setScheduleId(schedule.getScheduleId());vo.setLanType(schedule.getLanType());vo.setPrice(schedule.getPrice());result.add(vo);}return result;}}
ScheduleMapper.java
public interface ScheduleMapper {int deleteByPrimaryKey(Long id);int insert(Schedule record);Schedule selectByPrimaryKey(Long id);List<Schedule> selectAll();int updateByPrimaryKey(Schedule record);//通过filmId找场次List<Schedule> selectByFilmId(String filmId);}
ScheduleMapper.xml(之后若有自动生成的方法,不多展示)
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.duyi.dao.ScheduleMapper"><resultMap id="BaseResultMap" type="com.duyi.entity.Schedule"><id column="id" jdbcType="BIGINT" property="id" /><result column="schedule_id" jdbcType="VARCHAR" property="scheduleId" /><result column="schedule_time" jdbcType="TIMESTAMP" property="scheduleTime" /><result column="lan_type" jdbcType="VARCHAR" property="lanType" /><result column="price" jdbcType="DECIMAL" property="price" /><result column="room_id" jdbcType="VARCHAR" property="roomId" /><result column="room_name" jdbcType="VARCHAR" property="roomName" /><result column="film_id" jdbcType="VARCHAR" property="filmId" /><result column="film_name" jdbcType="VARCHAR" property="filmName" /></resultMap><delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from schedulewhere id = #{id,jdbcType=BIGINT}</delete><insert id="insert" parameterType="com.duyi.entity.Schedule">insert into schedule (id, schedule_id, schedule_time,lan_type, price, room_id,room_name, film_id, film_name)values (#{id,jdbcType=BIGINT}, #{scheduleId,jdbcType=VARCHAR}, #{scheduleTime,jdbcType=TIMESTAMP},#{lanType,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{roomId,jdbcType=VARCHAR},#{roomName,jdbcType=VARCHAR}, #{filmId,jdbcType=VARCHAR}, #{filmName,jdbcType=VARCHAR})</insert><update id="updateByPrimaryKey" parameterType="com.duyi.entity.Schedule">update scheduleset schedule_id = #{scheduleId,jdbcType=VARCHAR},schedule_time = #{scheduleTime,jdbcType=TIMESTAMP},lan_type = #{lanType,jdbcType=VARCHAR},price = #{price,jdbcType=DECIMAL},room_id = #{roomId,jdbcType=VARCHAR},room_name = #{roomName,jdbcType=VARCHAR},film_id = #{filmId,jdbcType=VARCHAR},film_name = #{filmName,jdbcType=VARCHAR}where id = #{id,jdbcType=BIGINT}</update><select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">select id, schedule_id, schedule_time, lan_type, price, room_id, room_name, film_id,film_namefrom schedulewhere id = #{id,jdbcType=BIGINT}</select><select id="selectAll" resultMap="BaseResultMap">select id, schedule_id, schedule_time, lan_type, price, room_id, room_name, film_id,film_namefrom schedule</select><select id="selectByFilmId" resultMap="BaseResultMap">select id, schedule_id, schedule_time, lan_type, price, room_id, room_name, film_id,film_namefrom schedule where film_id = #{filmId,jdbcType=VARCHAR}</select></mapper>
