1.select... for update锁表。
注意事项:
事务下使用,@Transactional
如果用主键,只锁住1行记录
如果不用主键,会锁住多条记录,mysql下测试,查询1条,锁住1行,查询2条,锁住2行。

网上不少文章说,没有用主键,会“锁表”,似乎不符合事实额。
比如,http://www.cnblogs.com/chenwenbiao/archive/2012/06/06/2537508.html

2.分页跳转的输入框,可以用html5中的input-number.
<input type="number" max="10" min="1"/>
右侧的“增加-减少”输入工具,可以+1或者-1。
如果用户手动输入,字符串等非数值是不允许的。

但是,存在1个问题。
用户输入的数字,不会检查是否满足 min 和 max属性的限制。

因此,需要额外写js事件去判断,blur失去焦点事件是可以的。

最后需要注意一点,jquery的attr获得是string类型,用户输入的页数 是否 满足min和max,需要先转换成int类型。

//解决分页输入,可能超过最大页数的问题。html5的input-number,不会检查用户的输入,是否满足min和max这2个属性
  $(function(){
 var toGoPage=$("#toGoPage");
 if(toGoPage){
  toGoPage.blur(function(){
 var page=parseInt(toGoPage.val());
 var maxPage=parseInt(toGoPage.attr("max"));
 var minPage=parseInt(toGoPage.attr("min"));
 console.log("page,"+page);
 console.log("maxPage,"+maxPage);
 console.log("minPage,"+minPage);
 if(page>maxPage){
 page=maxPage;
 }
 if(page<minPage){
 page=minPage;
 }
 toGoPage.val(page);
console.log("page,"+page);
  });
  console.log("bind2");
 }
  });
</script>
3.用字符串替换replace,而不是手动拼接字符串。
   var str ="<a href='{url}' target='_about'>{name}</a>";
   str=str.replace("{url}",url);
   str=str.replace("{name}",name);
   
   手动拼接字符串,太麻烦了,可读性很差。
4.jquery-easyui,格式化函数formatter.
注意事项:
a.formatter只需要填写函数的名字。
b.如果是格式化某个字段,field就是字段的名称。
c.如果格式化需要多个字段,field不能不写,同时不能写某个指定的字段,可以用个不存在的字段,比如“null”。
formatLink函数,就存在一定的技巧。field用不存在的“null”,挺好使的。

<#include "common/common.html"/>
<meta charset="UTF-8">
<table
    class="easyui-datagrid"   
    id="datagrid"  
         title="友情链接"  
         url="${base}/friendlink/list"
         toolbar="#toolbar" 
         rownumbers="true" 
         fitColumns="true"
         singleSelect="true"
         data-options="fit:false,border:false,pageSize:10,pageList:[5,10,15,20]" >  
    <thead>  
        <tr>
            <th field="id" width="5%">ID</th>  
            <th field="name" width="5%">名称</th>  
            <th field="url" width="35%">URL</th>
            <th field="remark" width="35%">备注</th>   
            <th field="sort" width="5%">排序</th> 
            <th field="null" width="10%" formatter="formatLink" width="5%">效果</th>    
        </tr>  
    </thead>  
</table> 
<script type="text/javascript">
function formatLink(val,row,index){
if(!row){console.error("The row is null,index="+index);return;};
   var name = row.name;
   var url = row.url;
   var str ="<a href='{url}' target='_about'>{name}</a>";
   str=str.replace("{url}",url);
   str=str.replace("{name}",name);
   return str;
   
}
</script>
5.电商系统,后端添加商品预览。
  后端再做一套“商品详细页面”,工作量巨大。
  解决方法:
    前端商品详细页面,改造下。
再增加一个url,service查询数据的时候,可以查询“未发布”的商品。
后端使用Iframe,嵌入前端新增的url。
“完全逼真”的预览效果。
6.Mybatis的“#{}”和"${}"
@Select("select * from ${tableName} where status =0 order by sort asc,id asc")
List<CommonCategory> listAll(@Param("tableName")String tableName);
这个地方的tableName只能用${},不会带“引号”。
str=abc, ${str}输出abc,#{str}输出 'abc'。

7.SpringMVC3的ResponseBody返回字符串乱码问题.
这个问题遇到很多次了,最近找不到那个配置了,网上找了一个。

引起乱码原因为spring mvc使用的默认处理字符串编码为ISO-8859-1,具体参考org.springframework.http.converter.StringHttpMessageConverter类中public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");

解决方法:

第一种方法:

对于需要返回字符串的方法添加注解,如下:

@RequestMapping(value="/getUsers", produces = "application/json; charset=utf-8")
 public String getAllUser() throws JsonGenerationException, JsonMappingException, IOException
 {
 List<User> users = userService.getAll();
 ObjectMapper om = new ObjectMapper();
 System.out.println(om.writeValueAsString(users));
 DataGrid dg = new DataGrid();
 dg.setData(users);
 return om.writeValueAsString(dg);
 }

此方法只针对单个调用方法起作用。

第二种方法:

在配置文件中加入

<mvc:annotation-driven>
     <mvc:message-converters register-defaults="true">
    <bean class="org.springframework.http.converter.StringHttpMessageConverter">
      <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />
    </bean>
   </mvc:message-converters>
     </mvc:annotation-driven>
参考:http://www.cnblogs.com/dyllove98/p/3180158.html

网上也有配置了mappingJacksonHttpMessageConverter,不需要。
但是如果配置了这个,访问一个url,比如http://localhost/category/list?amw=w,Chrome出现的“下载”,而不是直接展示内容了。
<mvc:annotation-driven >  
  <mvc:message-converters>
           <bean class="org.springframework.http.converter.StringHttpMessageConverter" >    
            <property name = "supportedMediaTypes">  
                <list>  
                     <value>text/plain;charset=UTF-8</value>  
                </list>  
            </property>  
           </bean>    
         <!--   <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">    
            <property name="supportedMediaTypes">    
                <list>    
                    <value>applicaton/json;charset=UTF-8</value>    
                </list>    
            </property>    
        </bean>     -->
       </mvc:message-converters> 
</mvc:annotation-driven>
8.Mybatis,There is no getter for property named 'merchantId' in 'class java.lang.String'。

如果mybatis语句中,增加了<if test="merchantId != null">这个if判断,需要给dao方法中,手动增加@Param("merchantId")。
List<String> findByShopId(@Param("merchantId")String merchantId);
<select id="findByShopId" resultType="string">
select id from mall_brand where 1 =1
<if test="merchantId != null">
and merchantType=2 and merchantId=#{merchantId}
</if>
</select>

如果只是#{}取值,不需要手动@Param("merchantId")。
List<String> findByShopId(String merchantId);
<select id="findByShopId" resultType="string">
select id from mall_brand where 1 =1
and merchantType=2 and merchantId=#{merchantId}
</select>
9. Spring直接把配置文件中的变量,放到Java变量中,放到xml中有时候不够直接。
@Value("${mailFromAddress}")
private String mailFromAddress;

10.SpringMVC发送邮件,必须设置“from”参数。
在这个bean中设置from参数不行,因为没有from这个参数。
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host">
<value>${mailServerHost}</value>
</property>
<property name="port">
<value>${mailServerPort}</value>
</property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.timeout">25000</prop>
</props>
</property>
<property name="username">
<value>${mailUserName}</value> <!-- 发送者用户名 -->
</property>
<property name="password">
<value>${mailPassword}</value> <!-- 发送者密码 -->
</property>
<!-- <property name="from">
 <value>${mailFromAddress}</value>
</property> -->
</bean>

@Resource
private JavaMailSender mailSender;

@Value("${mailFromAddress}")
private String mailFromAddress;

//在发送的时候,必须设置from
public void send(String subject,String content,String to){
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setSubject(subject);
simpleMailMessage.setText(content);
simpleMailMessage.setFrom(mailFromAddress);
simpleMailMessage.setTo(to);
mailSender.send(simpleMailMessage);
}

#配置参数
mailServerHost=
mailServerPort=25
mailUserName=
mailPassword=
mailFromAddress=
shopHost=

需要特别注意,userName是用来连接服务器的,from参数是可以手动设置的。
from和userName可以不同。

2016年工作中遇到的问题1-10:select-for-update锁表的更多相关文章

  1. MySQL中select * for update锁表的范围

    MySQL中select * for update锁表的问题 由于InnoDB预设是Row-Level Lock,所以只有「明确」的指定主键,MySQL才会执行Row lock (只锁住被选取的资料例 ...

  2. MySQL中select * for update锁表的问题

    MySQL中select * for update锁表的问题 由于InnoDB预设是Row-Level Lock,所以只有「明确」的指定主键,MySQL才会执行Row lock (只锁住被选取的资料例 ...

  3. MySQL中select * for update锁表的问题(转)

    由于InnoDB预设是Row-Level Lock,所以只有「明确」的指定主键,MySQL才会执行Row lock (只锁住被选取的资料例) ,否则MySQL将会执行Table Lock (将整个资料 ...

  4. mysql 中select for update 锁表的范围备注

    mysql的锁表范围测试 1.主键明确时,行级锁: 解释:指定主键并且数据存在时,仅锁定指定的行,其它行可以进行操作 实例:指定了锁定id=1的行且数据存在①,在更新1时lock wait超时②,但是 ...

  5. SEO工作中如何增加用户体验?10个细节要注意!

    我们一直在做的网站SEO工作,如果你认为它的目的仅仅是为了提高网站的排名那就错了,还有一个同样很重要的方面就是增加用户的体验,使网站更加符合网民的浏览习惯,需要做到这个方面的成功我们有10个小细节是需 ...

  6. 2016年工作中遇到的问题41-50:Dubbo注册中心奇葩问题,wifi热点坑了

    41.获得JSON中的变量.//显示json串中的某个变量,name是变量名function json(json,name){ var jsonObj = eval(json); return jso ...

  7. 事务处理操作(COMMIT,ROLLBACK)。复制表。更新操作UPDATE实际工作中一般都会有WHERE子句,否则更新全表会影响系统性能引发死机。

    更新操作时两个会话(session)同时操作同一条记录时如果没有事务处理操作(COMMIT,ROLLBACK)则会导致死锁. 复制表:此方法Oracle特有

  8. oracle中execute immediate的使用(select/insert/update/delete)(转)

    execute immediate的语法如下: execute immediate 'sql'; execute immediate 'sql_select' into var_1, var_2; e ...

  9. 数据库中Select For update语句的解析

    ----------- Oracle -----------------– Oracle 的for update行锁 键字: oracle 的for update行锁 SELECT-FOR UPDAT ...

随机推荐

  1. sass基础教程

    1. 使用变量; $highlight-color: #F90; .selected { border: 1px solid $highlight-color; } //编译后 .selected { ...

  2. ueditor1.4.3在.net环境下的vs开发工具中集成经验

    Ueditor是个非常不错的在线富文本编辑器,几个项目一直使用它.近期想更新版本号.发现新版1.4.3与旧版的部署方式全然不一样了.官网文档介绍的是直接放在iis下的部署说明,没有提到在vs开发工具中 ...

  3. Battle City

    Battle City Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7208   Accepted: 2427 Descr ...

  4. EOJ 1113 装箱问题

    有一个箱子容量为 V (正整数,0≤V≤20000),同时有 n 个物品(0<n≤30),每个物品有一个体积(正整数).要求从 n 个物品中,任取若干个装入箱内,使箱子的剩余空间为最小. Inp ...

  5. 用dom4j解析xml文件并执行增删改查操作

    转自:https://www.aliyun.com/jiaocheng/1339446.html xml文件: <?xml version="1.0" encoding=&q ...

  6. 27. Remove Element[E]移除元素

    题目 Given an array nums and a value val, remove all instances of that value in-place and return the n ...

  7. [Luogu1273] 有线电视网

    [Luogu1273] 有线电视网 题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树 ...

  8. JavaScript的switch循环

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  9. 【Arduino】基于arduino的激光坦克

    历经了总共40来个小时,终于将这个激光坦克做好了. 这是本人的第一件像样的arduino作品. 用arduino为主控制器,配有32路舵机驱动板(在这有些大材小用了),以及一个wr703n的路由器当做 ...

  10. hdu3926 Hand in Hand 判断同构

    因为每个人小朋友只有两只手,所以每个点最多只有2度.图有可能是环.链,以及环和链构成的复杂图. 如何判断两幅图是否相似呢?判断相似是判断两幅图的圈的数量,以及构成圈的点数是否相同.还有判断链的数目和构 ...