数据库三级分类如何用SSM的Controller+Service+mapper.xml+jsp实现 三级联动下拉框,显示不了数据库数据

数据库三级分类如何用SSM的Controller+Service+mapper.xml+jsp实现 三级联动下拉框

img

TestMapper.xml


```xml

mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sdwu.mapper.TestMapper">
    <resultMap id="BaseResultMap" type="com.sd.pojo.Category">
        <result column="CTG_ID" property="ctg_id"/>
        <result column="PRODUCT_CATALOG_CODE_1" property="ctg_code1"/>
        <result column="PRODUCT_CATALOG_NAME_1" property="ctg_name1"/>
        <result column="PRODUCT_CATALOG_CODE_2" property="ctg_code2"/>
        <result column="PRODUCT_CATALOG_NAME_2" property="ctg_name2"/>
        <result column="PRODUCT_CATALOG_CODE_3" property="ctg_code3"/>
        <result column="PRODUCT_CATALOG_NAME_3" property="ctg_name3"/>
    resultMap>
    
    <select id="findProvince"   resultType="Category">
        select distinct PRODUCT_CATALOG_NAME_1 from AMS_CATEGORY
    select>

    <select id="findCityByName" parameterType="String" resultType="Category">
        select distinct PRODUCT_CATALOG_NAME_2 from AMS_CATEGORY where PRODUCT_CATALOG_NAME_1=#{ctg_name1}
    select>

    <select id="findCountyByName" parameterType="String"   resultType="Category">
        select distinct PRODUCT_CATALOG_NAME_3 from AMS_CATEGORY where PRODUCT_CATALOG_NAME_2 =#{ctg_name2}
    select>

mapper>


TestMapper



import com.sd.pojo.Category;

import java.util.List;

public interface TestMapper {
        public List findProvince();
        public List findCityByName(String pr_name);
        public List findCountyByName(String ci_name);
    }

TestService




import com.sd.pojo.Category;
import javax.annotation.Resource;

import java.util.List;

@Resource
public interface TestService {
        public List findProvince();
        public List findCityByName(String pr_name);
        public List findCountyByName(String ci_name);
    }


TestServiceImpl



import com.sd.mapper.CategoryMapper;
import com.sd.mapper.TestMapper;
import com.sd.pojo.Category;
import com.sd.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("testService")
@Transactional
public class TestServiceImpl implements TestService {
    @Autowired
    private TestMapper testMapper;
    @Override
    public List findProvince() {
        return this.testMapper.findProvince();
    }

    @Override
    public List findCityByName(String pr_name) {
        // TODO Auto-generated method stub
        return this.testMapper.findCityByName(pr_name);
    }

    @Override
    public List findCountyByName(String ci_name) {
        // TODO Auto-generated method stub
        return this.testMapper.findCountyByName(ci_name);
    }

}

TestController



import com.sd.pojo.Category;
import com.sd.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;


    @Controller
    public class TestController {
        @Autowired
        private TestService testService;

        @RequestMapping("findProvince")
        public String findProvince(Model model) {
            List province = testService.findProvince();
            model.addAttribute("province", province);
            return "/test/test111.jsp";
        }

        @RequestMapping(value = "/testjson1/{pr_name}", method = RequestMethod.GET)
        @ResponseBody
        public Object testJson1(@PathVariable("pr_name") String pr_name, Model model) throws IOException {
            List city = testService.findCityByName(pr_name);
            return city;
        }

        @RequestMapping(value = "/testjson2/{ci_name}", method = RequestMethod.GET)
        @ResponseBody
        public Object testJson2(@PathVariable("ci_name") String ci_name, Model model) throws IOException {
            List county = testService.findCountyByName(ci_name);
            return county;
        }
    }

test111.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
    <head>
        <title>Titletitle>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript"
                src="../js/jquery-1.9.1.min.js">
        script>
        <script type="text/javascript">
            function testJson1(){
                var pr_name = $("#province").val();
                $("#city").html('');
                $.ajax({
                    url : "${pageContext.request.contextPath}/testjson1/"+pr_name,
                    type : "GET",
                    dataType : "json",
                    success : function(data){
                        if(data!=null){
                            $(data).each(function(index){
                                $("#city").append(
                                    '+'">'+data[index].ci_name+''
                                );
                            });
                        }
                    }
                });
            }
            function testJson2(){
                var ci_name = $("#city option:selected").val();
                $("#county").html('');
                $.ajax({
                    url : "${pageContext.request.contextPath }/testjson2/"+ci_name,
                    type : "GET",
                    dataType : "json",
                    success : function(data){
                        if(data!=null){
                            $(data).each(function(index){
                                $("#county").append(
                                    '+'">'+data[index].co_name+''
                                );
                            });
                        }
                    }
                });
            }
        script>
    head>
    <body>

        <select name="province"  id="province">
            <option value="">------请选择省份-----option>
            <c:forEach items="${province}" var="c1">
                <option value="${c1.pr_name}" οnclick="testJson1()">${c1.pr_name}option>
            c:forEach>
        select>
        <select name="city" id="city" οnclick="testJson2()">
            <option value="">------请选择城市-----option>
        select>
        <select name="county" id="county" >
            <option value="">------请选择县城-----option>
        select>
    body>
html>




为什么页面显示不出来数据库里的数据?

img

  • 这篇博客: 计算机毕业设计-长途汽车售票系统SSM+JSP【代码讲解+安装调试+文档指导】中的 购买车票Mapper.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.dao.GoumaichepiaoMapper">
      <resultMap id="BaseResultMap" type="com.entity.Goumaichepiao">
        <id column="id" jdbcType="INTEGER" property="id" />
    	<result column="checibianhao" jdbcType="VARCHAR" property="checibianhao" />
        <result column="zhandianmingcheng" jdbcType="VARCHAR" property="zhandianmingcheng" />
        <result column="dizhi" jdbcType="VARCHAR" property="dizhi" />
        <result column="chepaihao" jdbcType="VARCHAR" property="chepaihao" />
        <result column="fadaodi" jdbcType="VARCHAR" property="fadaodi" />
        <result column="chufashijian" jdbcType="VARCHAR" property="chufashijian" />
        <result column="piaojia" jdbcType="VARCHAR" property="piaojia" />
        <result column="shuliang" jdbcType="VARCHAR" property="shuliang" />
        <result column="zongjiage" jdbcType="VARCHAR" property="zongjiage" />
        <result column="lianxidianhua" jdbcType="VARCHAR" property="lianxidianhua" />
        <result column="goumaishijian" jdbcType="VARCHAR" property="goumaishijian" />
        <result column="goumairen" jdbcType="VARCHAR" property="goumairen" />
        <result column="iszf" jdbcType="VARCHAR" property="iszf" />
        
        <result column="addtime" jdbcType="VARCHAR" property="addtime" />
      </resultMap>
      <sql id="Base_Column_List">
        id, checibianhao,zhandianmingcheng,dizhi,chepaihao,fadaodi,chufashijian,piaojia,shuliang,zongjiage,lianxidianhua,goumaishijian,goumairen, iszf,addtime
      </sql>
      <select id="quchongGoumaichepiao"  parameterType="java.util.Map" resultMap="BaseResultMap" >
        select 
        <include refid="Base_Column_List" />
        from goumaichepiao 
        where goumairen = #{goumairen,jdbcType=VARCHAR} limit 0,1
      </select>
     <select id="getCount"   resultType="int" parameterType="java.util.Map" >
        select  count(*) from goumaichepiao  where 1=1
        <if test="checibianhao!=null">and checibianhao like  concat('%',#{checibianhao,jdbcType=VARCHAR},'%')</if>
         <if test="zhandianmingcheng!=null">and zhandianmingcheng like  concat('%',#{zhandianmingcheng,jdbcType=VARCHAR},'%')</if>
         <if test="dizhi!=null">and dizhi like  concat('%',#{dizhi,jdbcType=VARCHAR},'%')</if>
         <if test="chepaihao!=null">and chepaihao like  concat('%',#{chepaihao,jdbcType=VARCHAR},'%')</if>
         <if test="fadaodi!=null">and fadaodi like  concat('%',#{fadaodi,jdbcType=VARCHAR},'%')</if>
         <if test="chufashijian!=null">and chufashijian like  concat('%',#{chufashijian,jdbcType=VARCHAR},'%')</if>
         <if test="piaojia!=null">and piaojia like  concat('%',#{piaojia,jdbcType=VARCHAR},'%')</if>
         <if test="shuliang1!=null">and shuliang &gt;=  concat('',#{shuliang1,jdbcType=VARCHAR},'')</if>
         <if test="shuliang2!=null">and shuliang &lt;=  concat('',#{shuliang2,jdbcType=VARCHAR},'')</if>
         <if test="zongjiage!=null">and zongjiage like  concat('%',#{zongjiage,jdbcType=VARCHAR},'%')</if>
         <if test="lianxidianhua!=null">and lianxidianhua like  concat('%',#{lianxidianhua,jdbcType=VARCHAR},'%')</if>
         <if test="goumaishijian1!=null">and goumaishijian &gt;=  concat('',#{goumaishijian1,jdbcType=VARCHAR},'')</if>
         <if test="goumaishijian2!=null">and goumaishijian &lt;=  concat('',#{goumaishijian2,jdbcType=VARCHAR},'')</if>
         <if test="goumairen!=null">and goumairen like  concat('%',#{goumairen,jdbcType=VARCHAR},'%')</if>
         <if test="iszf!=null">and iszf like  concat('%',#{iszf,jdbcType=VARCHAR},'%')</if>
      </select> 
      <select id="getAll"   resultMap="BaseResultMap" parameterType="java.util.Map" >
        select   <include refid="Base_Column_List" /> from goumaichepiao  where 1=1
        <if test="goumairen!=null">
        and goumairen =#{goumairen}
        </if>
      </select>
      
      <select id="getsygoumaichepiao1"   resultMap="BaseResultMap" parameterType="java.util.Map" >
        select   <include refid="Base_Column_List" /> from goumaichepiao  where 1=1
        limit 0,5
      </select>
      <select id="getsygoumaichepiao2"   resultMap="BaseResultMap" parameterType="java.util.Map" >
        select   <include refid="Base_Column_List" /> from goumaichepiao  where 1=1
        limit 0,5
      </select>
      <select id="getsygoumaichepiao3"   resultMap="BaseResultMap" parameterType="java.util.Map" >
        select   <include refid="Base_Column_List" /> from goumaichepiao  where 1=1
        limit 0,5
      </select>
      
       <select id="getByPage" parameterType="java.util.Map" resultMap="BaseResultMap">
         select  <include refid="Base_Column_List" /> 
         from goumaichepiao where 1=1 
         <if test="checibianhao!=null">and checibianhao like  concat('%',#{checibianhao,jdbcType=VARCHAR},'%')</if>
         <if test="zhandianmingcheng!=null">and zhandianmingcheng like  concat('%',#{zhandianmingcheng,jdbcType=VARCHAR},'%')</if>
         <if test="dizhi!=null">and dizhi like  concat('%',#{dizhi,jdbcType=VARCHAR},'%')</if>
         <if test="chepaihao!=null">and chepaihao like  concat('%',#{chepaihao,jdbcType=VARCHAR},'%')</if>
         <if test="fadaodi!=null">and fadaodi like  concat('%',#{fadaodi,jdbcType=VARCHAR},'%')</if>
         <if test="chufashijian!=null">and chufashijian like  concat('%',#{chufashijian,jdbcType=VARCHAR},'%')</if>
         <if test="piaojia!=null">and piaojia like  concat('%',#{piaojia,jdbcType=VARCHAR},'%')</if>
         <if test="shuliang1!=null">and shuliang &gt;=  concat('',#{shuliang1,jdbcType=VARCHAR},'')</if>
         <if test="shuliang2!=null">and shuliang &lt;=  concat('',#{shuliang2,jdbcType=VARCHAR},'')</if>
         <if test="zongjiage!=null">and zongjiage like  concat('%',#{zongjiage,jdbcType=VARCHAR},'%')</if>
         <if test="lianxidianhua!=null">and lianxidianhua like  concat('%',#{lianxidianhua,jdbcType=VARCHAR},'%')</if>
         <if test="goumaishijian1!=null">and goumaishijian &gt;=  concat('',#{goumaishijian1,jdbcType=VARCHAR},'')</if>
         <if test="goumaishijian2!=null">and goumaishijian &lt;=  concat('',#{goumaishijian2,jdbcType=VARCHAR},'')</if>
         <if test="goumairen!=null">and goumairen like  concat('%',#{goumairen,jdbcType=VARCHAR},'%')</if>
         <if test="iszf!=null">and iszf like  concat('%',#{iszf,jdbcType=VARCHAR},'%')</if>
    	 order by id desc
         <if test="pageno!=null and pageSize!=null">
         limit #{pageno},#{pageSize}
         </if>
         </select>
    	 
      <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select 
        <include refid="Base_Column_List" />
        from goumaichepiao
        where id = #{id,jdbcType=INTEGER}
      </select>
      <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from goumaichepiao
        where id = #{id,jdbcType=INTEGER}
      </delete>
      <insert id="insert" parameterType="com.entity.Goumaichepiao">
        insert into goumaichepiao (id, checibianhao,zhandianmingcheng,dizhi,chepaihao,fadaodi,chufashijian,piaojia,shuliang,zongjiage,lianxidianhua,goumaishijian,goumairen, addtime)
        values (#{id,jdbcType=INTEGER}, #{checibianhao,jdbcType=VARCHAR},#{zhandianmingcheng,jdbcType=VARCHAR},#{dizhi,jdbcType=VARCHAR},#{chepaihao,jdbcType=VARCHAR},#{fadaodi,jdbcType=VARCHAR},#{chufashijian,jdbcType=VARCHAR},#{piaojia,jdbcType=VARCHAR},#{shuliang,jdbcType=VARCHAR},#{zongjiage,jdbcType=VARCHAR},#{lianxidianhua,jdbcType=VARCHAR},#{goumaishijian,jdbcType=VARCHAR},#{goumairen,jdbcType=VARCHAR}, #{addtime,jdbcType=VARCHAR})
      </insert>
      <insert id="insertSelective" parameterType="com.entity.Goumaichepiao">
        insert into goumaichepiao
        <trim prefix="(" suffix=")" suffixOverrides=",">
          <if test="id != null">
            id,
          </if>
          <if test="checibianhao != null"> checibianhao, </if>
          <if test="zhandianmingcheng != null"> zhandianmingcheng, </if>
          <if test="dizhi != null"> dizhi, </if>
          <if test="chepaihao != null"> chepaihao, </if>
          <if test="fadaodi != null"> fadaodi, </if>
          <if test="chufashijian != null"> chufashijian, </if>
          <if test="piaojia != null"> piaojia, </if>
          <if test="shuliang != null"> shuliang, </if>
          <if test="zongjiage != null"> zongjiage, </if>
          <if test="lianxidianhua != null"> lianxidianhua, </if>
          <if test="goumaishijian != null"> goumaishijian, </if>
          <if test="goumairen != null"> goumairen, </if>
          
          <if test="addtime != null">
            addtime,
          </if>
          
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
          <if test="id != null">
            #{id,jdbcType=INTEGER},
          </if>
          <if test="checibianhao != null"> #{checibianhao,jdbcType=VARCHAR},</if>
          <if test="zhandianmingcheng != null"> #{zhandianmingcheng,jdbcType=VARCHAR},</if>
          <if test="dizhi != null"> #{dizhi,jdbcType=VARCHAR},</if>
          <if test="chepaihao != null"> #{chepaihao,jdbcType=VARCHAR},</if>
          <if test="fadaodi != null"> #{fadaodi,jdbcType=VARCHAR},</if>
          <if test="chufashijian != null"> #{chufashijian,jdbcType=VARCHAR},</if>
          <if test="piaojia != null"> #{piaojia,jdbcType=VARCHAR},</if>
          <if test="shuliang != null"> #{shuliang,jdbcType=VARCHAR},</if>
          <if test="zongjiage != null"> #{zongjiage,jdbcType=VARCHAR},</if>
          <if test="lianxidianhua != null"> #{lianxidianhua,jdbcType=VARCHAR},</if>
          <if test="goumaishijian != null"> #{goumaishijian,jdbcType=VARCHAR},</if>
          <if test="goumairen != null"> #{goumairen,jdbcType=VARCHAR},</if>
          
          <if test="addtime != null">
            #{addtime,jdbcType=VARCHAR},
          </if>
          
        </trim>
      </insert>
      <update id="updateByPrimaryKeySelective" parameterType="com.entity.Goumaichepiao">
        update goumaichepiao
        <set>
    	  <if test="checibianhao != null"> checibianhao = #{checibianhao,jdbcType=VARCHAR},</if>
          <if test="zhandianmingcheng != null"> zhandianmingcheng = #{zhandianmingcheng,jdbcType=VARCHAR},</if>
          <if test="dizhi != null"> dizhi = #{dizhi,jdbcType=VARCHAR},</if>
          <if test="chepaihao != null"> chepaihao = #{chepaihao,jdbcType=VARCHAR},</if>
          <if test="fadaodi != null"> fadaodi = #{fadaodi,jdbcType=VARCHAR},</if>
          <if test="chufashijian != null"> chufashijian = #{chufashijian,jdbcType=VARCHAR},</if>
          <if test="piaojia != null"> piaojia = #{piaojia,jdbcType=VARCHAR},</if>
          <if test="shuliang != null"> shuliang = #{shuliang,jdbcType=VARCHAR},</if>
          <if test="zongjiage != null"> zongjiage = #{zongjiage,jdbcType=VARCHAR},</if>
          <if test="lianxidianhua != null"> lianxidianhua = #{lianxidianhua,jdbcType=VARCHAR},</if>
          <if test="goumaishijian != null"> goumaishijian = #{goumaishijian,jdbcType=VARCHAR},</if>
          <if test="goumairen != null"> goumairen = #{goumairen,jdbcType=VARCHAR},</if>
          
          <if test="addtime != null">
            addtime = #{addtime,jdbcType=VARCHAR},
          </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
      </update>
      
      <update id="updateByPrimaryKey" parameterType="com.entity.Goumaichepiao">
        update goumaichepiao
        set checibianhao = #{checibianhao,jdbcType=VARCHAR},zhandianmingcheng = #{zhandianmingcheng,jdbcType=VARCHAR},dizhi = #{dizhi,jdbcType=VARCHAR},chepaihao = #{chepaihao,jdbcType=VARCHAR},fadaodi = #{fadaodi,jdbcType=VARCHAR},chufashijian = #{chufashijian,jdbcType=VARCHAR},piaojia = #{piaojia,jdbcType=VARCHAR},shuliang = #{shuliang,jdbcType=VARCHAR},zongjiage = #{zongjiage,jdbcType=VARCHAR},lianxidianhua = #{lianxidianhua,jdbcType=VARCHAR},goumaishijian = #{goumaishijian,jdbcType=VARCHAR},goumairen = #{goumairen,jdbcType=VARCHAR},  addtime = #{addtime,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER}
      </update>
    </mapper>
    

     更多项目推荐:计算机毕业设计项目

    公众号:IT跃迁谷【更多精彩文章】

    ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓如果大家有任何疑虑,请在下方位置详细咨询。