java学习日记-各种巨坑总结

Struts
  1. struts.xml文件路径是在src根目录下
  2. 如地址栏路径中是在stu包下,则相关的action也要放在stu包下
Mybatis
  1. 有缓存,查询查不到数据库中最新的值,所以改库后查询,查出的值不是最新的
  2. entity中Date属性要定义成java.sql.Date
  3. where子句动态SQL写法
  4. <select id="selectById" resultMap="empMap">
        <include refid="SELECT_SQL6"/>		
    	 <where>
    	    emp.status=1
    	    <if test="sid!=null">
    	        and emp.id like '%'||#{sid}||'%'
    	    </if> 
    	    <if test="lowSal!=null">
    		and emp.salary &gt;=#{lowSal}
    	    </if> 		
    	    <if test="highSal!=null">
    		and emp.salary &lt;=#{highSal}
    	    </if>
    	</where>
    </select>
jsp
  1. 页面中value=后面一定不能加换行,空格等符号
  2. 有链接的地方&前不能换行
s:if
1、分页样式设置
<s:iterator begin="1" end="totalPage" var="i">  	
	<s:if test="currentPage==#i">
		<s:property />
	</s:if>
	<s:else>
		<a href="${ pageContext.request.contextPath }/emp/splitPage?currentPage=<s:property />"
		><s:property /></a>
	</s:else>     
</s:iterator>
2、显示所有部门
<select name="student.team_id">
	<s:iterator value="teams">											
		<option value=<s:property value="team_id"/>>
			<s:property value="team_name"/>
		</option>
	</s:iterator> 
</select>
3、修改页显示已选部门
<select name="student.team_id">
	<s:iterator value="teams" var="team">											
		<option value=<s:property value="team_id"/>
			<s:if test="student.team.team_name==#team.team_name">
				selected='selected'
			</s:if>
		>
			<s:property value="team_name"/>
		</option>
	</s:iterator>
</select>
4、列表页性别翻译
<s:if test='gender=="f"'>女</s:if>
<s:else>男</s:else>
5、修改页显示已选性别
<input type="radio" name="student.gender" value="m"
	<s:if test='student.gender=="m"'>checked='checked'</s:if>/>男
<input type="radio" name="student.gender" value="f"
	<s:if test='student.gender=="f"'>checked='checked'</s:if>/>女
js
1. 表单验证时,匿名函数返回值需要加if-else判断,保证每个分支都有返回值
2. 动态表格批量删除方法
function remove(){
	var tbBoxs = document.getElementsByName('tbBox');     
	for(var i=0,flag=true;i<tbBoxs.length;flag?i++:i){
		if(tbBoxs[i].checked){
		    var tr = tbBoxs[i].parentNode.parentNode;
			// 获取tbody对象 | tbody是行的父节点
			var tb = tr.parentNode;
			// 移除当前行
			tb.removeChild(tr); 
			flag=false;
		}
		else flag=true;
	}
}
Ajax
1. js动态值传给action
var ori = $('#oriInput').val();
xhr.send('oriPwd='+ori);
2. 注意用成员变量收参时,别忘加get-set方法
3. action方法中输出字符不要有换行
HttpServletResponse response = ServletActionContext.getResponse();
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(ckOriPwd){
            out.print("ok");
        }
        else{
            out.print("no");
        }
        return null;
4. 上传文件回显,注意当前页面与upload文件相对路径,可以先在本地upload上试,路径对了再传
MyEclipse
1、复制项目时,右键新项目,选择Properties,输入WEB,将Web context-root改成新项目名称

Oracle

1、查询1997年每个月入职的员工数,入职时间hire_date

select to_char(hire_date,'mm'),count(*) from employees
where to_char(hire_date,'yyyy') = '1997'
group by to_char(hire_date,'mm');

2、查询工资排名3-5的员工id及其姓名

select * from
(select t1.*,rownum r
from (select * from employees order by salary desc) t1 )
where  r>=3 and r <=5;

3、between and效率不如>= and <=

4、导入数据:cmd-sqlplus-连接数据库,start/@后拖入sql脚本。

5、空值既不在where XXX=xxx的查询结果集中,也不在where XXX!=xxx的查询结果集中,只存在于where XXX is null的结果集中。

java

1、判断集合为空

if(queryByCategoryId.isEmpty()){
                products = queryByCategoryId;               
            }
            else {
                products = splitPage(queryByCategoryId);
            }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值