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>

    当能力支撑不了野心时,就该静下心来学习!
  • 相关阅读:
    FCK常用Js,获取FCK内容,统计FCK字数,向FCK写入指定代码
    asp 点击链接 下载图片文件
    使用微软的 Visual Studio International Pack 1.0 进行网站简体与繁体的互转和得到汉字、拼音、笔画
    mysql alter 语句用法,添加、修改、删除字段等
    C#指定窗口显示位置的方法
    Soukey采集软件源码
    [转](收藏)《博客园精华集》分类索引
    YUI CSS Foundation讲座 博客文库 博客园
    sql group by 和having
    sql 多表查询
  • 原文地址:https://www.cnblogs.com/1234cjq/p/5707673.html
Copyright © 2011-2022 走看看