項目的各種配置開始出現混亂的現象了
在只有一個人開發的情況下也開始感受到維護一個項目的難度。
之前明明還好用的東西,轉眼就各種莫名其妙的報錯,完全不知道為什么。
今天一天的工作基本上就是整理各種配置。
再加上之前數據庫設計出現了問題,要增加一個表,改幾個名字,刪幾個字段……真是頭大
##1、gradle排除依賴
在打war包的時候出現了spring-boot與dubbo框架自帶的spring2.5.6沖突的情況,于是學會了這么一招:
//僅在本地執行時使用,不添加到warprovidedRuntime 'org.springframework:spring:2.5.6.SEC03'//排除依賴compile(project(':client-core')) {exclude group:"org.springframework", module:"spring:2.5.6.SEC03"}
復制代碼
配置寫在gradle的dependencies中,將這個包排除在外,用新的spring4就好了。
不禁吐槽dubbo是有多古老的框架嘛?為啥不支持新一代的spring啊?
然而今天配置完后出現了找不到spring-servlet.xml配置文件的問題。明明放在一起的spring-core.xml都能找到的說。此問題留待明天解決。
##2、spring使用配置文件
在本地環境、測試環境、生產環境的各種切換當真是非常操蛋的一件事情。
為此做的第一件工作是統一數據源,redis、mysql等數據源都分別創建唯一的bean用spring注入。算是很基本的做法。
這兩天發現就算是每次改spring的xml文件也是個挺操蛋的事情。于是小小的嘗試了一下這個標簽:
<context:property-placeholder location="/config.properties"/>
復制代碼
應該算是新增的標簽,在網上搜索到的方法要活生生的寫一個bean配置,這個能省事不少。
這樣直接用${prop.name}就可以添加配置咯~
##3、mybatis聯合查詢~ 還記得上次說的mybatis聯合查詢功能么,很快就用上了。 為了能利用這個功能,我活生生的修改了數據庫的結構。其實也是一開始設計的不標準。這次徹底符合2NF的設計,就可以愉快的聯合查詢了。 作為這次修改的教訓: 不要把m:n的關聯寫到數據表里面! 不要把m:n的關聯寫到數據表里面! 不要把m:n的關聯寫到數據表里面! 多建一個關聯表不會死人。 第一個聯合查詢的代碼貼上來留作紀念~
<resultMap type="com.xinou.lolttery.server.bean.Team" id="teamResultMap"><!-- 屬性名和數據庫列名映射 --><id property="id" column="team_id" /><result property="shortname" column="team_shortname" /><result property="logo" column="team_logo" /></resultMap><resultMap type="com.xinou.lolttery.server.bean.MatchTeam" id="linkResultMap"><!-- 屬性名和數據庫列名映射 --><id property="id" column="link_id" /><result property="teamid" column="link_teamid" /><result property="place" column="link_place" /></resultMap><resultMap id="appMatchList" type="com.xinou.lolttery.server.bean.result.AppMatchList"><id property="id" column="id" /><result property="zone" column="zone" /><result property="winner" column="winner" /><result property="zonename" column="zonename" /><result property="zonelogo" column="zonelogo" /><result property="matchdate" column="matchdate" /><result property="matchmode" column="matchmode" /><result property="result" column="result" /><collection property="teams" ofType="com.xinou.lolttery.server.bean.Team" resultMap="teamResultMap"/><collection property="links" ofType="com.xinou.lolttery.server.bean.MatchTeam" resultMap="linkResultMap"/></resultMap><select id="queryByTime" parameterType="long" resultType="com.xinou.lolttery.server.bean.result.AppMatchList" resultMap="appMatchList">select m.*,mt.id link_id,mt.teamid link_teamid,mt.place link_place,t.id team_id,t.shortname team_shortname,t.logo team_logo, z.name zonename,z.logo zonelogo from((lt_match m left join lt_match_team mt on mt.matchid = m.id ) left join lt_team t on t.id=mt.teamid)left join lt_match_zone z on m.zone = z.id where m.matchdate < #{0} limit 0,20</select>
復制代碼