【Lolttery】项目开发日志 - (三)维护好一个项目好难

项目的各类配置开始出现混乱的现象了mysql

在只有一我的开发的状况下也开始感觉到维护一个项目的难度。redis

以前明明还好用的东西,转眼就各类莫名其妙的报错,彻底不知道为何。spring

今天一天的工做基本上就是整理各类配置。sql

再加上以前数据库设计出现了问题,要增长一个表,改几个名字,删几个字段……真是头大数据库

 

一、gradle排除依赖mybatis

在打war包的时候出现了spring-boot与dubbo框架自带的spring2.5.6冲突的状况,因而学会了这么一招:app

//仅在本地执行时使用,不添加到war
    providedRuntime '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都能找到的说。此问题留待明天解决。ide

 

二、spring使用配置文件

在本地环境、测试环境、生产环境的各类切换当真是很是操蛋的一件事情。

为此作的第一件工做是统一数据源,redis、mysql等数据源都分别建立惟一的bean用spring注入。算是很基本的作法。

这两天发现就算是每次改spring的xml文件也是个挺操蛋的事情。因而小小的尝试了一下这个标签:

<context:property-placeholder location="/config.properties"/>

应该算是新增的标签,在网上搜索到的方法要活生生的写一个bean配置,这个能省事很多。

这样直接用${prop.name}就能够添加配置咯~

 

三、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 &lt; #{0} limit 0,20
    </select>
相关文章
相关标签/搜索