2014年工作中遇到的20个问题:41-60

41.Maven工程中,src/main/webapp目录结构太深,不方便点击。
在普通的Web工程中,WebContent直接就在项目的根目录下,打开页面比较方便。
因此,为了方便,把Maven工程的src/main/webapp直接作为“Source  Code”加入到Build Path下,
这样可以方便编辑webapp目录中的页面。
但是,导致的结果是:Maven打包时,不会把webapp目录下的页面打包到target目录对应的文件中。
因此,把src/main/webapp作为Source Code目录,从而方便编辑web页面的方式,是不行的。


另外,加入build path时,貌似会自动修改Jetty的Run Configuration的选项,
WebApp Folder:src/main/webapp被改成了 build/classed/main/webapp。


这个问题还有待进一步尝试~

最终结论,把src/main/webapp作为Source Code目录是可行的,可以减少编辑web页面的点击次数,非常方便。
上面的问题,根本原因是“不知道怎么修改了Run Configuration-Jetty的Webapp Folder”,错误地改成了“build/classed/main/webapp”
而不是正确的"src/main/webapp"。


终于找到了一种比较好的方法,在Maven工程中,也可以象普通项目那样,方便地编辑页面了。


42.Freemarker数字转时间
http://my.oschina.net/u/1458693/blog/293697


如果字段是字符串格式,就要先转换为number,支持链式调用
<#setting datetime_format="yyyy-MM-dd HH:mm"/>
${profile.createTime?number?number_to_datetime}


${"1411009099377"?number?number_to_datetime}


43.SpringMVC,modelMap中加入参数,如果跳转到某个url,会把这些参数也附在url后面。


@RequestMapping(value = "/testReceive")
public String testReceive(HttpServletResponse response,
ReceivePaymentModel receivePaymentModel,ModelMap map) {
map.addAttribute("test", "Test");
return "redirect:http://www.baidu.com";
}
会跳转到;http://www.baidu.com?test=Test


44.Sitemesh显示title
直接通过$来获取几个元素,${title}、 ${head}、${base}、${title}、${body}




JSP需要引入Taglib
<%@taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<sitemesh:head/>


<sitemesh:title/>


在Freemarker中,没有Taglib,直接用${title}。




45.Maven配置war包
  <build>
    <finalName>funds</finalName>
  如果pom.xml文件中,有finalName这个配置,生成的war和jar包的格式是funds.war,即不带版本号。
  
  如果没有配置,默认的格式是funds-1.0.0.war。
  
46.tomcat启动的时候增加全局变量,-Dp2p_config_dir=/user/local/p2p
Spring项目中的properties配置文件可以和项目分离。
 <!-- 将多个配置文件读取到容器中,交给Spring管理 -->  
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
               <!--  这里支持多种寻址方式:classpath和file  
              <value>classpath:config/demo.properties</value>
              --> 
              <!-- 推荐使用file的方式引入,这样可以将配置和代码分离 -->  
              <value>classpath:config/activemq.properties</value> 
              <value>classpath*:config/domain.properties</value>
<value>classpath:file:/usr/local/p2p</value> 
              <value>classpath*:${p2p_config}/config/domain.properties</value>
            </list>
        </property>
    </bean>




47.Spring和属性文件<context:property-placeholder location="classpath:config/global.properties" ignore-unresolvable="true"/>。


配置之后,就可以使用${jdbc.properties}。
这个地方有疑问的是:"location"这个地方是不能使用${}的。


使用PropertiesFactoryBean,可以使用${}了。为了达到一个目的“指定配置文件的完整路径时,需要一个${}计算相对路径,从而达到Web工程和属性配置完全分离”。
<bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
              <value>${p2p.config_path}config/p2p_db.properties</value>
            </list>
        </property>
    </bean>
<!-- <context:property-placeholder location="${p2p.config_path}/p2p_db.properties" ignore-unresolvable="true"/> -->

用了PropertiesFactoryBean之后,values中可以使用${}了,但是接下来的
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxConnectionsPerPartition" value="15" />
</bean>
${jdbc.driverClassName}没有解析。

现在的结论是,PropertiesFactoryBean和PropertyPlaceholderConfigurer都不能解决问题额。




<context:property-placeholder location="${p2p.config_path}config/p2p_db.properties" ignore-unresolvable="true"/>
p2p.config_path在JVM中指定参数。


48.单词拼写错误,导致按名字找不到,而按照类型找到多个。
@Resource
private Cache defaultCache;//"defalut"
“单词拼写错误很难找到”,某某同事的一个失误,花了不少时间。


49.mysql日期属性定义为bigint,而不是date,是为了“把日期作为索引,bigint效率更高”。


50.创建存储过程失败。

线上原服务器成功创建,root账户;
本地成功创建,root账户。
新服务器非root账户,报错,很可能是权限不足导致的。
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQ
L DATA in its declaration and binary logging is enabled (you *might* want to use
 the less safe log_bin_trust_function_creators variable)
 
51.
class Service{
@Transactional(readOnly=true,propagation=Propagation.REQUIRES_NEW)
public Long add();

public Long add2(){
  this.add2();
}

add2方法没有事务,要想让声明式事务Transactional起作用,需要经过代理类,一个类内部之间的方法调用,没有经过代理类,
类之间的方法调用才会经过代理类。
}


52.JSP等页面中,引入css时,需要放在“<head></head>”里,否则SiteMesh可能不会把它加进去。
<head>
<link rel="stylesheet" type="text/css" href="/public/hao/themes/default/css/index/index.css?v=20141010">
</head>


53.引入JS的时候,多个JS可能存在依赖关系,被其它js依赖的需要优先引入。


54.securecrt这块SSH访问工具可以记住用户名和密码,不用重新输入,而Putty就不行。

  公司某台服务器密码超级长,用putty不记住密码,简直折磨死人额。


55.Tomcat增加自定义配置参数。
set JAVA_OPTS = %JAVA_OPTS% -Dp2p.config_path=file:C:/Users/Administrator/git/p2p2/yiqihao/


56.运行Windows程序的时候,报错,但不知道错误原因。
  可以通过控制台cmd运行,能够看到更详细的错误提示。


57. Freemarker的include语法。
  在A页面引用,<#include "user_menu.ftl" />,提示user_menu.ftl找不到。
  按照HTML语法,不是“/”开头的url,应该是相对于当前页面的路径猜对,结果Freemarker中不是。
  <#include "common/user_menu.ftl" />,这样才行额。


58.Mybatis的Mapper不允许重名。
   Dao接口的方法虽然可以重名,但在运行的时候会报错。
   “Mapped Statements collection already contains value for com.p2p.user.dal.dao.LoanInfoDao.list”。
   
59.Mybatis的分页插件PageHelper的PageInfo不能用在WebService中。
Caused by: java.lang.NoSuchMethodError: com.github.pagehelper.PageInfo.<init>(Ljava/lang/Object;)V
at com.github.pagehelper.PageInfoFactory.createPageInfo(PageInfoFactory.java)
... 85 more
最奇怪的问题是“com.github.pagehelper.PageInfoFactory”这个类根本不存在PageHelper类库里额。

 解决办法是:新建一个简单的不依赖Page类的PageInfo2,把PageInfo的结果copy到PageInfo2。
 WebService接口:
    public PageInfo2 queryLogPageByConditions();


这个构造函数有点复杂
public PageInfo(List list) {
        if (list instanceof Page) {
            Page page = (Page) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.startRow = page.getStartRow();
            this.endRow = page.getEndRow();
            this.total = page.getTotal();
            this.pages = page.getPages();
            this.list = page;
        }
    }


60.数据库中一个字段apr存储了年利率apr(0.15),而Java的Model定义的数据类型是Integer,结果页面中显示的值总是0。
   因为int的默认值0,一直觉得数据没有查询出来。但是实际执行的sql语句,却查询出来了。
   最后突然才明白,数据类型不匹配,数据库的Double 0.15转换成Java的Integer总是0。
   修改Java Model的属性apr为Double类型就可以了。



原文地址:https://www.cnblogs.com/qitian1/p/6463199.html