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可以不同。

转载于:https://www.cnblogs.com/qitian1/p/6462489.html

2016年工作中遇到的问题1-10:select-for-update锁表相关推荐

  1. 【转】MySQL中select * for update锁表的问题

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

  2. 2016年工作中遇到的问题31-40

    31.Spring和Dubbo中都有@Service注解,需要注意. import com.alibaba.dubbo.config.annotation.Service; import org.sp ...

  3. 2016年工作中遇到的问题11-20

    11.SpringMVC的PathVariable. @PathVariable("id") Integer id; @RequestParam Integer id; 使用了&q ...

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

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

  5. oracle execute immediate 报错,oracle中execute immediate的使用(select/insert/update/delete)...

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

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

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

  7. 发布订阅模式,在工作中它的能量超乎你的想象

    不同的语言-相同的模式 最近在看设计模式的知识,而且在工作当中,做一些打点需求的时候,正好直接利用了发布订阅模式去实现的,这让我对发布订阅这种设计模式更加的感兴趣了,于是借此机会也和大家说说这个好东东 ...

  8. 2016年度工作总结

    一想起来今天全办公室人都在写年终总结的场景,不由自主的笑开了颜,因为我把一名程序媛的年终总结硬生生的写成了一篇"散文",而且还是很"冒牌"的总结,以下就是&qu ...

  9. 遥感在计算机领域的应用,遥感技术在测绘工作中的应用分析

    孟亭记 摘 要:在信息化发展的当下,遥感技术是众多新技术中的一种,在测绘工作中发挥着重要作用.在科学技术的快速发展中,计算机技术与互联网技术不断得到普及,大大增加了应用范围,促使遥感技术在测绘工作中的 ...

最新文章

  1. POJ 1001(高精度乘法 java的2种解法)
  2. andpods授权码订单号分享_不要再让你的接口裸奔了,Boot快速尝试OAuth2密码和授权码模式...
  3. 郑州网络推广教你如何“悄悄”做网站SEO,惊艳竞争对手?
  4. linux-shell命令之cat【输出档案内容】
  5. 【Processing学习】 - 公交车马路动态绘制
  6. 面试官:说一下Jena推理
  7. 安卓学习笔记12:安卓按键事件
  8. 我年薪百万,孩子教育花掉一半
  9. [转]使用 HTML5 索引型数据库的待办事项简要列表
  10. linux离线安装pg数据库
  11. 英寸、磅等单位的换算
  12. UC浏览器设置代理服务器JAVA_uc浏览器让JAVA手机变“聪明”的方法
  13. uniapp 微信小程序配置全局主题色、实现动态修改主题色
  14. fdisk和parted对磁盘的分区总结
  15. Android 学习记录(持续更新)
  16. GB28181 协议 SIP
  17. 快速上手百度大脑人体关键点识别
  18. Windows Server 2016 基本设置
  19. Caffe 源码 - BatchNorm 层与 Scale 层
  20. 软件著作权提交源代bai码格式_软件著作权提交源代码格式要求

热门文章

  1. minHash最小哈希原理
  2. Java基础:请求重定向与请求转发的比较
  3. jquery获取iframe里的js事件
  4. Gridview导出到EXCEL
  5. 使用分层网络模型的两个优点是什么_从零开始学网络|搞懂OSI参考模型和TCP/IP分层模型,看这篇文章就够了...
  6. eclipse maven打包_我的Java Web之路47 - 使用Maven改造租房网工程
  7. 浅谈ARMv8-A系列CPU的架构
  8. 操作系统之进程和线程
  9. ByteBufferMessageSet分析
  10. Apache 虚拟主机