<select id="selectChaptersWithResources" resultMap="ChapterDtoMap"> SELECT c.id AS chapter_id, c.parent_id, c.name, c.courseId, sc.id AS sub_chapter_id, sc.parent_id AS sub_parent_id, sc.name AS sub_name, sc.courseId AS sub_courseId, r.id AS resource_id, r.section_id, r.name AS resource_name FROM chapter c LEFT JOIN chapter sc ON c.id = sc.parent_id LEFT JOIN resource r ON sc.id = r.section_id WHERE c.courseId = #{courseId} AND c.parent_id IS NULL </select>
</mapper>
三、其他文件
1. Mapper
language-java
1 2 3 4
public interface ChapterMapper { List<ChapterDto> selectChaptersWithResources(Long courseId); }
2. Service
language-java
1 2 3 4 5 6 7 8 9 10 11
@Service public class ChapterService { @Autowired private ChapterMapper chapterMapper;
public List<ChapterDto> getChaptersWithResources(Long courseId) { return chapterMapper.selectChaptersWithResources(courseId); } }
3. Controller
language-java
1 2 3 4 5 6 7 8 9 10 11 12 13 14
@RestController @RequestMapping("/chapters") public class ChapterController { @Autowired private ChapterService chapterService;
@GetMapping("/{courseId}") public ResponseEntity<List<ChapterDto>> getChapters(@PathVariable Long courseId) { List<ChapterDto> chapters = chapterService.getChaptersWithResources(courseId); return ResponseEntity.ok(chapters); } }
@Data public class XueChengPlusException extends RuntimeException {
private String errMessage;
public XueChengPlusException() { super(); }
public XueChengPlusException(String errMessage) { super(errMessage); this.errMessage = errMessage; }
public static void cast(CommonError commonError){ throw new XueChengPlusException(commonError.getErrMessage()); } public static void cast(String errMessage){ throw new XueChengPlusException(errMessage); }
}
language-java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
@Getter public enum CommonError { UNKOWN_ERROR("执行过程异常,请重试。"), PARAMS_ERROR("非法参数"), OBJECT_NULL("对象为空"), QUERY_NULL("查询结果为空"), REQUEST_NULL("请求参数为空");
public class Server { public static void main(String[] args) throws Exception { //1. create server socket DatagramSocket socket = new DatagramSocket(8889); //2. create packet byte[] bytes = new byte[1024 * 64]; DatagramPacket packet = new DatagramPacket(bytes, bytes.length); while (true) { //3.receive socket.receive(packet);
public class Client { public static void main(String[] args) throws Exception { //1.create socket and send link request to server Socket socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 8889); //2.get socket output for write message to server OutputStream os = socket.getOutputStream(); //3.package low os to high os DataOutputStream dos = new DataOutputStream(os);
Scanner sc = new Scanner(System.in); while (true) { System.out.println("请说"); String s = sc.nextLine(); if (s.equals("exit")){ break; } //4.write message dos.writeUTF(s); dos.flush();//立刻发送 System.out.println("已发送~"); }