七月[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

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