课堂作业功能1
Html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <table border="1" id="tab"> <tr th:each="line:${line1}"> <td><p th:text="${line.id}"></p></td> <td><p th:text="${line.station}"></p></td> </tr> </table> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <table border="1" id="tab"> <tr th:each="line:${line2}"> <td><p th:text="${line.id}"></p></td> <td><p th:text="${line.station}"></p></td> </tr> </table> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <table border="1" id="tab"> <tr th:each="line:${line3}"> <td><p th:text="${line.id}"></p></td> <td><p th:text="${line.station}"></p></td> </tr> </table> </body> </html>
XML:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.subway.dao.queryDao"> <select id="select" parameterType="map" resultType="line"> select * from line1 <where> <if test="id !=null"> and id=#{id} </if> <if test="station !=null"> and station=#{station} </if> </where> </select> <select id="select2" parameterType="map" resultType="line2"> select * from line2 <where> <if test="id !=null"> and id=#{id} </if> <if test="station !=null"> and station=#{station} </if> </where> </select> <select id="select3" parameterType="map" resultType="line3"> select * from line3 <where> <if test="id !=null"> and id=#{id} </if> <if test="station !=null"> and station=#{station} </if> </where> </select> </mapper>
controller:
package com.subway.controller; import com.subway.pojo.Line; import com.subway.service.impl.queryServiceImpl; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.HashMap; import java.util.List; /** * @version 1.0 * @Author: wuyi * @date 2022/3/25 11:12 */ @Controller public class Query { private final queryServiceImpl queryService; public Query(queryServiceImpl queryService) { this.queryService = queryService; } @RequestMapping("line1") public String equerry(Model model){ // String userId = request.getParameter("line"); HashMap<String,String> map= new HashMap<>(); List<Line> line1 = queryService.select(map); System.out.println(line1); model.addAttribute("line1",line1); return "./one/query1"; } @RequestMapping("line2") public String eequerry(Model model){ // String userId = request.getParameter("line"); HashMap<String,String> map= new HashMap<>(); List<Line> line2 = queryService.select2(map); System.out.println(line2); model.addAttribute("line2",line2); return "./one/query2"; } @RequestMapping("line3") public String eeequerry(Model model){ // String userId = request.getParameter("line"); HashMap<String,String> map= new HashMap<>(); List<Line> line3 = queryService.select3(map); System.out.println(line3); model.addAttribute("line3",line3); return "./one/query3"; } }
接口与pojo略过
servixce:
package com.subway.service.impl; import com.subway.dao.queryDao; import com.subway.pojo.Line; import com.subway.pojo.Line2; import com.subway.service.queryService; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; /** * @version 1.0 * @Author: wuyi * @date 2022/3/25 10:40 */ @Service("queryService") public class queryServiceImpl implements queryService { private final queryDao queryDao; public queryServiceImpl(com.subway.dao.queryDao queryDao) { this.queryDao = queryDao; } //线路查询 @Override public List<Line> select(Map map) { return queryDao.select(map); } public List<Line> select2(Map map) { return queryDao.select2(map); } public List<Line> select3(Map map) { return queryDao.select3(map); } }

浙公网安备 33010602011771号