七月[jsp,sql]

一. jsp页面,城市复选框状态

描述:当查询某一条数据的时候,根据后台返回的数据,对复选框进行勾选

--- jsp页面中的复选框
 <div id="other">
         <input type="checkbox" id="city2" name="city" value="0537"/>&nbsp;济宁
         <input type="checkbox" id="city3" name="city" value="0530"/>&nbsp;菏泽
         <input type="checkbox" id="city4"name="city" value="0539"/>&nbsp;临沂 <br/>
      
</div>
  • 复选框选中的方法
<script type="text/javascript">
        //城市复选框选中
        $(document).ready(function () {
            var boxObj = $("input:checkbox[name='city']");
            //var citylist = '${citylist}';
            var citylist = '${popubBean.city}';     //获取后台传递过来的城市列表数据
            var city = citylist.split(',');         //以逗号进行分割
            for (j = 0; j < boxObj.length; j++) {       
                for (i = 0; i < citylist.length; i++) {
                    if (boxObj[j].value == city[i]) {   //如果复选框中的值与城市的值一样    
                        boxObj[j].checked = true;       //将复选框的状态选中
                        break;
                    }
                }
            }
        });
        
</script>

数据库

    • 数据库表,多表联查

数据库的表设计

schedule double(6,2) DEFAULT NULL COMMENT “…”
double(6,2):第一个参数表示总长度,第二个参数表示几位小数。

多表联查

<!--条件查询,根据 种类,格式 进行查询 多对多关联查询-->
    <resultMap id="picMap" type="com.xwtec.sucai.bean.PictrueBean">
        <id property="id" column="id"/>
        <result property="imgesUrl" column="imgesUrl"/>
        <result property="uploadDate" column="uploadDate"/>
        <result property="imgFormat" column="imgFormat"/>
        <result property="imgSize" column="imgSize"/>
        <result property="imgTitle" column="imgTitle"/>
        <result property="imgName" column="imgName"/>
        <result property="useTool" column="useTool"/>
        <result property="onlinPoint" column="onlinPoint"/>

        <collection property="sortBeanList" ofType="com.xwtec.sucai.bean.SortBean" javaType="list">
            <id property="id" column="sortId"/>
            <result property="sortName" column="sortName"/>
            <result property="sortKeyWord" column="sortKeyWord"/>
        </collection>
    </resultMap>
    
<!--三表联查-->
    <select id="findByQy" resultMap="picMap">
        SELECT *
        FROM
        t_pictrue_qy qy
        inner JOIN
        t_sort_and_pic sp
        on
        qy.id=sp.sapPicId
        inner JOIN
        t_sort s
        on
        sp.sapSortId=s.sortId
        <where>
            <if test="sortKeyWord !=null and sortKeyWord != ''">
                and sortKeyWord=#{sortKeyWord}
            </if>
            <if test="imgFormat !=null and imgFormat !=''">
                and imgFormat=#{imgFormat}
            </if>
            <if test="imgTitle !=null and imgTitle !=''">
                and imgTitle like '%${imgTitle}%'
            </if>
        </where>
    </select>
  • property :实体类中的属性
  • column :数据库表中的字段
  • 注意 :如果想要在后边添加日期排序,需要在写一条查询语句
......
order by  updateTime  desc

删除语句

  • 多表联删
delete qy,tsp
from t_pictrue_qy qy
inner join t_sort_and_pic tsp
on qy.id=tsp.sapPicId
where qy.id=1563499409795

slq语句

TRUNCATE TABLE t_fans_record_copy1
TRUNCATE TABLE t_test2

-- 创建测试表
CREATE TABLE `t_test3` (
  `id` int(100) NOT NULL AUTO_INCREMENT COMMENT '自增序列 唯一索引',
  `openid` varchar(200) DEFAULT NULL COMMENT '微信用户openid',
	`phone` varchar(11) DEFAULT NULL COMMENT '绑定手机号',
	 PRIMARY KEY (`id`)
) 

-- 查出所有有重复记录的所有记录
SELECT count(openid)
from t_test2
where openid !=NULL 
GROUP BY phone HAVING count(openid)>1;


-- 
SELECT count(*)
from t_fans_record_copy1

-- 删除重复语句并保留一条数据的SQL
DELETE FROM 表名 WHERE id NOT IN(SELECT * FROM(SELECT id FROM 表名 GROUP BY 分组名)AS b)  

-- 更新数据(将\\N 替换成 null)
UPDATE t_test2 set phone = null WHERE phone ='\\N'

-- 查询是否有没有更新成功的
SELECT * FROM t_test2 where phone ='\\N'

--  条件复制
INSERT into t_fans_record_copy1(
	openid,
	city,
	subscribe_status,
	bind_status,
	bind_form,
	bind_time,
	phone
) select openid,
	'535',
	'cancel',
	case when phone is not null then 'binding' else null end,
	case when phone is not null then 'general' else null end,
	case when phone is not null then now() else null end,
	phone from t_test2


-- 全复制 
	INSERT into t_fans_record
	(openid,
	unionid,
	nickname,
	headimgurl,
	city,
	subscribe_status,
	subscribe_from,
	subscribe_time,
	unsubscribe_time,
	bind_status,
	bind_form,
	bind_time,
	phone,
	sex,
	wechat_id,
	referee_openid,
	remark)
	SELECT 
	openid,
	unionid,
	nickname,
	headimgurl,
	city,
	subscribe_status,
	subscribe_from,
	subscribe_time,
	unsubscribe_time,
	bind_status,
	bind_form,
	bind_time,
	phone,
	sex,
	wechat_id,
	referee_openid,
	remark
	FROM t_fans_record_copy1
	
	--2019年9月4日23:51:28 将一张表的数据更新到另外一张表
	UPDATE t_fans_record tr,t_fans_record_xiangtong tx 
set tr.subscribe_status=tx.subscribe_status,
tr.subscribe_from=tx.subscribe_from,
tr.subscribe_time=tx.subscribe_time,
tr.unsubscribe_time=tx.unsubscribe_time,
tr.bind_status=tx.bind_status,
tr.bind_form=tx.bind_form,
tr.bind_time=tx.bind_time,
tr.phone=tx.phone,
tr.sex=tx.sex,
tr.referee_phone=tx.referee_phone,
tr.county=tx.county
WHERE tr.openid=tx.openid and tr.city=tx.city

  • case … when

case when 条件 then 值 else 值2 end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章