20 problems encountered during work in 161: 161-180,2014-180
161. The Dao of Mybatis cannot find the ing configuration in xml, possibly because the namespace in xml configuration is incorrect.
Org. apache. ibatis. binding. BindingException: Invalid bound statement (not found): com. p2p. user. dal. dao. MemberPointDao. selectForUpdateByUserId
<Mapper namespace = "com. p2p. user. dal. dao. MemberPointDao"> the name must be correct.
162. Use annotation @ ResultMap to map the ResultType of Mybatis.
@ ResultMap ("MemberPointResultMap ")
@ Select ("select" + columns + "from" + tableName + "where user_id =#{ userId} for update ")
MemberPoint selectForUpdateByUserId (String userId );
<Mapper namespace = "com. p2p. user. dal. dao. MemberPoint">
<ResultMap id = "MemberPointResultMap" type = "MemberPoint">
<Result column = "user_id" property = "userId"/>
<Result column = "produce_cumulative" property = "produceCumulative"/>
<Result column = "consume_cumulative" property = "consumeCumulative"/>
<Result column = "level" property = "level"/>
</ResultMap>
</Mapper>
163. change the password of the mysql database.
Log on to the Linux server and log on to mysql. The system prompts that/tmp/socket cannot be connected.
You can log on to and view mysql remotely through dos locally, but you do not have the permission to access the mysql database. Non-root users do not have the permission to change their passwords.
The strange thing is that the socket used by online mysql is installed in its own directory. Why can't I log on to mysql normally?
Only the root user can modify the password.
164. asynchronous search and table display make it difficult to display the user's query conditions, as well as highlight and other styles.
The method of opening a new page synchronously facilitates you to search for the current link and facilitates search engine optimization.
For background management systems or internal systems, AJAX is more convenient and friendly.
165. Confuse Freemarker, Java-EL expressions, and Mybatis expressions.
<# Assign queryUrl = "$ {base}/loan/list.html? Time =$ {page. time} & term =$ {page. term} "/>
Only $ {} can be used here, and the variable in the Java background is used.
# Only the Freemarker internal and Mybatis configuration files are supported.
166. Do not use left-join or other multi-table join queries. You can use only single-table queries and Java programs to easily implement multi-table queries,
Limitation: Single-table queries are not suitable for multi-table joint search and paging is required.
167. There are two types of paging URLs.
If the input url contains a parameter, it contains "?" The following parameters do not need to be added? .
<# If url? Contains ('? ') =-1>
<# Assign pageUrl = "$ {url }? PageNum =$ {pageNum} & pageSize =$ {data. pageSize} ">
<# Else>
<# Assign pageUrl = "$ {url} & pageNum =$ {pageNum} & pageSize =$ {data. pageSize}">
</# If>
This problem also indicates that pagination URLs are used to open a new page and Freemarker is used to generate the page. It is troublesome to maintain parameters.
If you use the AJAX paging component without refreshing the page, it is much easier to maintain the paging query parameters in JS.
168. JQuery POST sending parameters are required.
$. Post (
"/Article/comment/list. json ",{
"Params [article_id]": $ {article. id },
PageNo: pageNo
}
Correct syntax: article_id, "params. article_id", "params [article_id]"
If the parameter name contains "() []", it must be enclosed in quotation marks.
169. The Mybatis attribute must exist.
The input object must have attributes such as maxDate. Otherwise, an error is returned.
Why is this problem?
SearchListPage (PageVo );
SearchListPage (LoanPageVo );
LoanPageVo has the maxDate attribute, but PageVo does not.
The page with search may receive more conditions. For common queries elsewhere, maxDate and other fields are not required. To set the parameters more common,
You can use PageVo without using LoanPageVo, but you finally encountered the above problem.
The method is to separate the two dao to simplify the processing.
<Select id = "searchListPage" resultType = "java. util. Map">
Select t .*
From p2p_transfer t left join p2p_loan_info l on t. lid =
L. lid
Where 1 = 1
<If test = "maxDate! = Null ">
And # {maxDate}> = t. exptime
</If>
<If test = "minDeadline! = Null ">
And deadline >=# {minDeadline}
</If>
<If test = "maxDeadline! = Null ">
And deadline & lt ;=#{ maxDeadline}
</If>
Order by id desc
</Select>
170. "greater than" and "less than" in Freemarker ".
Use "gt" and "lt ".
<# If category. count gt 0>
Popular Science:
Gt: great
Lt: less
171. SpringMVC2 access modes, which support both dynamic rendering and JSON format.
Http://fansunion.cn/case.json
Http://fansunion.cn/case.html
<Bean
Class = "org. springframework. web. servlet. view. ContentNegotiatingViewResolver">
<Property name = "defaultContentType" value = "application/json"/>
<Property name = "mediaTypes">
<Map>
<Entry key = "html" value = "text/html"/>
<Entry key = "json" value = "application/json"/>
<Entry key = "xml" value = "application/xml"/>
</Map>
</Property>
<Property name = "defaultViews">
<List>
<Bean
Class = "org. springframework. web. servlet. view. json. MappingJacksonJsonView">
</Bean>
<Bean id = "marshallingView"
Class = "org. springframework. web. servlet. view. xml. MarshallingView">
<Property name = "marshaller">
<Bean id = "xstreampolicaller" class = "org. springframework. oxm. xstream. xstreampolicaller">
<Property name = "autodetectAnnotations" value = "true"/>
</Bean>
</Property>
<Property name = "contentType" value = "application/xml"/>
</Bean>
</List>
</Property>
</Bean>
It is convenient to convert dynamic rendering to JSON format.
172. SpringMVC @ ModelAttribute.
@ ModelAttribute
Protected void menuColumnList (Model model ){
List <Map <String, Object> menuColumnList = initMenuColumnList ();
Model. addAttribute ("menuColumnList", menuColumnList );
CurrentColumn (model, 0 );
}
The above method is defined in BaseController. ArticleController inherits BaseController, so every method of ArticleController responds
Run the menuColumnList method to query menu data.
However, in the backend management system, menus are fixed and not dynamic, so no query is required.
The solution is to create an AdminBaseController and put all the methods shared by the Controller Into the Controller. The original BaseController can be renamed
FrontController.
173. AJAX method error.
A Web Front-end colleague encapsulated the AJAX method and reported an error during use.
Why? For the same parameter, $. ajax and $. post are both acceptable. As long as ptp. ajax is used,
After comparison, you will know right or wrong.
174. The substring header does not end with a packet.
Java. lang. String. substring public String substring (int beginIndex, int endIndex) returns a new String, which is a substring of this String.
This substring starts from the specified beginIndex until the character at the index endIndex-1.
Therefore, the length of the substring is endIndex-beginIndex.
175. SpringMVC interceptor excluded some paths.
<Mvc: interceptors>
<Mvc: interceptor>
<Mvc: mapping path = "/*"/>
<Mvc: exclude-mapping path = "/resource/**"/>
<Bean class = "com. xinlong. cms. front. interceptor. CmsFrontInterceptor"> </bean>
</Mvc: interceptor>
</Mvc: interceptors>
There is another problem here: the exclude-mapping label is not supported by the spring-mvc-3.0.xsd,
This configuration can be obtained through http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdin spring-mvc-3.2.xsd,
SpringMVC header Introduction
Xsi: schemaLocation ="
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-3.0.xsd
Http://www.springframework.org/schema/mvc
Http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
Http://www.springframework.org/schema/util
Http://www.springframework.org/schema/util/spring-util-3.0.xsd>
Use spring-mvc-3.2.xsd.
176. replace into is similar to insert. The difference is that replace into first tries to insert data into the table,
1. If this row of data is found in the table (determined based on the primary key or unique index), delete the row of data and insert new data.
2. Otherwise, insert new data directly.
Note that the table to which data is inserted must have a primary key or a unique index! Otherwise, replace into inserts data directly, which leads to duplicate data in the table.
The table has three fields: uid, name, and value.
Primary Index: It can be uid, uid, or uname.
Replace into p2p_user_info (user_id, info_name, info_value) values (# {uid}, 'borrower _ auth', # {auth}
177. Database and Map are case sensitive.
Database query results are saved in map. database fields are in upper case, for example, USER_INFO. When Map is used to retrieve data, it uses the lower case "user_info ".
Change the database to lowercase.
178. Repeated definitions of the same elements in Html may cause many strange issues.
For example, if you define two titles, <title> </title>; <title> 1 </title>, the title on the page is blank, and the browser defaults it to the current url.
Define two identical IDs. The js value is incorrect.
Two input boxes with the same name will be submitted when the form is submitted, but 1st may be received by the backend, and may not be desired.
179. SQL query sorting is unstable.
Select * from user order by id desc;
The primary key id is unique and the sorting is unique.
Select * from user order by name desc;
If two identical names, such as "boy", are met, the query results are unstable.
I used mysql-front to query and found that the results were the same.
But another database query tool, as shown in the web interface, is different each time.
The sorting is not stable, which makes people feel unstable.
180. SpringMVC security issues.
@ RequestMapping ("list ")
Public void list (PageVo form, Model model ){
Form. handleSearch ();
PageVo page = withdrawService. listPage (form );
Form. resetSearch ();
Model. addAttribute ("res", 1 );
Model. addattrils ("data", PageUtils. data (page ));
}
List. json directly responds to requests in json format.
There is a problem here. If the attributes placed in model. addAttribute are redundant, in this way, the front-end obtains the json
Additional information, such as the user information currently logged on, is stored.
Model. addAttribute ("user", user );
It is better to manually respond to requests in JSON format and send only necessary fields.
First: http://fansunion.cn/article/detail/559.html