• springmvc实现查数据下拉框


    jsp页面部分   遍历输出数据库信息

    <div class="weui_cell">
    <div class="weui_cell_hd">
    <label class="weui_label">店名</label>
    </div>

    <select class="weui_select" id="shopid" name="shopid">
    <c:forEach items="${list}" var="shop">                    //list为后台传回来的集合名称   shop为下列对象调用
    <option value="${shop.id}" id="option2">${shop.shopname}</option>     //shop.shopname    shopname为实体类字段
    </c:forEach>
    </select>
    </div>

    ------------------------------------------------------------------------------------------------------------------------------------------------------

    controller部分   

    @Controller
    @RequestMapping("/phone")
    public class PhoneContorller {

    @Autowired
    public BtyShopService btyShopService;      //调用需要用的Service

    @RequestMapping(value = { "/Create"}, method = RequestMethod.GET)
    public String createPage(Model model, ServletRequest request) {
    List<BtyShop> list = btyShopService.ListAll();             //get方法加载     Service的方法调用    执行sql语句

    request.setAttribute("list", list);     //"list"为传回前台的集合对象
    List<Region> region= regionService.ListAll();
    request.setAttribute("region", region);
    return "phone/Create";               //返回页面信息
      }

    }

    -----------------------------------------------------------------------------------------------------------------------------------------

    Mapper部分

    package com.mybatis.mapper;

    import java.util.List;

    import com.mybatis.model.Region;

    public interface RegionMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Region record);

    int insertSelective(Region record);

    Region selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Region record);

    int updateByPrimaryKey(Region record);

    List<Region> getAll();      //为被调用的使用方法
    }

    ---------------------------------------------------------------------------------------------------------------------------------------------

    Service部分

    package com.mybatis.service;

    import java.util.List;

    import org.springframework.stereotype.Service;

    import com.mybatis.mapper.RegionMapper;
    import com.mybatis.model.Region;

    @Service
    public class RegionService {
    @javax.annotation.Resource
    private RegionMapper regionMapper;    // 调用Mapper

    public List<Region> ListAll(){
    return regionMapper.getAll();     //调用方法
    }
    }

    ------------------------------------------------------------------------------------------------------------------------------------------------------

    Mapper方法里用到的sql语句

    <mapper>

    <resultMap id="BaseResultMap" type="com.mybatis.model.Region" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="regionName" property="regionname" jdbcType="VARCHAR" />
    <result column="tel" property="tel" jdbcType="INTEGER" />
    <result column="text" property="text" jdbcType="VARCHAR" />
    </resultMap>

    <sql id="Base_Column_List" >
    id, regionName, tel, text
    </sql>

    <select id="getAll" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from t_region
    </select>

    </mapper>

    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    ARM64架构下登录mysql出错:mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file:
    Linux按文件名搜索命令
    kubernetes集群部署nacos:Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'MYSQL_SERVICE_HOST'
    kubernetes集群:gitlab搭建(ssh和http都能访问)
    centos7 逻辑卷缩容(xfs格式)翻车现场
    k8s集群:postgresql的pod启动失败
    no matches for kind "Deployment" in version "apps/v1beta1"
    Kubernetes集群搭建以及部署高可用ingress
    centos7安装mysql5.7
    kubernetes集群node节点重启docker的操作顺序
  • 原文地址:https://www.cnblogs.com/1234cjq/p/5707673.html
Copyright © 2020-2023  润新知