2016 problems encountered in the Work 1-10:select-for-update lock table

Source: Internet
Author: User



1.select.. for Update lock table.
Precautions:
Under Transaction, @Transactional
If you use a primary key, only 1 rows of records are locked
If you do not use the primary key, will lock many records, MySQL under test, query 1, lock 1 rows, query 2, lock 2 rows.


Many articles on the internet said that without the use of the primary key, will "lock the table", does not seem to meet the actual amount.
For example, http://www.cnblogs.com/chenwenbiao/archive/2012/06/06/2537508.html


2. Paging Jump input box, you can use HTML5 in the Input-number.
<input type= "number" max= "ten" min= "1"/>
The "Increase-decrease" input tool on the right can be +1 or-1.
A non-numeric value such as a string is not allowed if the user enters it manually.


However, there are 1 problems.
The number entered by the user does not check whether the limits of Min and Max properties are met.


Therefore, it is necessary to write an additional JS event to judge that Blur loses focus event is possible.


Finally, it should be noted that the attr of jquery is a string type, and the number of pages entered by the user satisfies min and Max and needs to be converted to the int type first.


Resolves a problem where paging input may exceed the maximum number of pages. HTML5 's input-number does not check the user's input and satisfies the 2 properties of Min and Max
$ (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 replace with a string instead of manually stitching the string.
var str = "<a href= ' {URL} ' target= ' _about ' >{name}</a>";
Str=str.replace ("{URL}", url);
Str=str.replace ("{name}", name);

Manually stitching strings, too cumbersome, very poor readability.
4.jquery-easyui, the Format function formatter.
Precautions:
A.formatter only needs to fill in the name of the function.
B. If you are formatting a field, field is the name of the fields.
C. If formatting requires multiple fields, field cannot write, and cannot write a specified field, you can use a non-existent field, such as "null".
Formatlink function, there is a certain skill. field is very good with non-existent "null".


< #include "common/common.html"/>
<meta charset= "UTF-8" >
<table
Class= "Easyui-datagrid"
Id= "DataGrid"
title= "Links"
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%" > Name </th>
<th field= "url" width= "35%" >URL</th>
<th field= "Remark" width= "35%" > Remarks </th>
<th field= "Sort" width= "5%" > Sort </th>
<th field= "null" width= "10%" formatter= "Formatlink" width= "5%" > Effects </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. E-commerce system, back end Add product preview.
Back end to do a set of "Product detail Page", the workload is huge.
Workaround:
Front End Product detail page, under renovation.
When you add a url,service query data, you can query for "unpublished" items.
The backend uses an IFRAME, embedding the new URL into the front end.
A "completely realistic" preview effect.
6.Mybatis "#{}" and "${}"
@Select ("Select * from ${tablename} where status =0 order by sort asc,id ASC")
List<commoncategory> Listall (@Param ("TableName") String tableName);
The tablename of this place can only be used with ${}, with no "quotes".
STR=ABC, ${str} output ABC,#{STR} output ' abc '.


7.SPRINGMVC3 Responsebody Returns a string garbled problem.
This problem encountered many times, recently can't find that configuration, the Internet to find a.


The default processing string encoded as iso-8859-1 for spring MVC, which causes garbled characters, For specific reference, public static final Charset Default_charset in the Org.springframework.http.converter.StringHttpMessageConverter class = Charset.forname ("iso-8859-1");


Workaround:


The first method:


Add annotations for methods that need to return a string, as follows:


@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);
}


This method works only for a single invocation method.


The second method:


In the configuration file, add


<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>
Reference: http://www.cnblogs.com/dyllove98/p/3180158.html


There are also mappingjacksonhttpmessageconverter configured on-line, not required.
But if you configure this, access a URL, such as "download" that appears in Http://localhost/category/list?amw=w,Chrome, instead of displaying the content directly.
<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 '.


If the MyBatis statement is added <if test= "Merchantid! = NULL" > This if judgment is required for the DAO method, manually add @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>

If only #{} is evaluated, no manual @param ("Merchantid") is required.
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 directly places the variables in the configuration file into the Java variables, which are sometimes not straightforward enough to put into XML.
@Value ("${mailfromaddress}")
Private String mailfromaddress;

10.SpringMVC send a message, you must set the "from" parameter.
It is not possible to set the from parameter in this bean because there is no from this parameter.
<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> <!--sender User name--
</property>
<property name= "Password" >
<value>${mailPassword}</value> <!--sender Password--
</property>
<!--<property name= "from" >
<value>${mailFromAddress}</value>
</property>
</bean>


@Resource
Private Javamailsender MailSender;

@Value ("${mailfromaddress}")
Private String mailfromaddress;

When sending, you must set the 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=


It is important to note that username is used to connect to the server, and the from parameter can be set manually.
The From and username can be different.




2016 problems encountered in the Work 1-10:select-for-update lock table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.