zoukankan      html  css  js  c++  java
  • 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>

    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    tomcatserver解析(五)-- Poller
    最新版OpenWrt编译教程,解决依赖问题
    操作系统2015(四川大学软件学院)
    Kafka专业监控系统Kafka Eagle:支持kerberos认证,并且对接星环TDH集群
    logstash导出ElasticSearch数据到CSV及同步两套ES的数据研究
    hive通过like方式查询多个值
    hadoop balancer平衡集群各节点数据
    Inceptor命令04-表
    Inceptor命令02-命令使用
    Inceptor命令01-表介绍
  • 原文地址:https://www.cnblogs.com/1234cjq/p/5707673.html
Copyright © 2011-2022 走看看