1:Eclipse 一直不停 building workspace… 解决办法
先将项目clean
然后把Maven Project Builder禁用掉就OK了。
在项目右键点击->Properties->Builder->Maven Project Builder取消勾选就可以了。其他保持不变
2:web.xml is missing and is set to true
这时候需要右击项目——>Java EE Tools——>Generate Deployment Descriptor Stub.然后系统会在src/main/webapp/WEB_INF文件加下创建web.xml文件。错误解决!
3 :执行clean tomcat7:run命令报错:
Could not find artifact com.taotao:taotao-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 11
原因:在本地仓库找不到父工程taotao-parent,先将父工程发布到本地仓库。
4:Unknown return value type [java.lang.Integer]
后台和前台都可以正常执行,但是不会打印删除成功
原因:前台接受的是json格式的数据,但是后台传递的是int型数据
5:
错误显示
原因:
@RequestMapping(“/toSaveType”)有两个相同的
6:今天做mybatis与spring整合的时候报了一个错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [D:\soft\eclipseMars\workspace\taotao-manager\taotao-manage-web\target\classes\spring\applicationContext-dao.xml]: Cannot resolve reference to bean 'classpath:mybatis/SqlMapConfig.xml' while setting bean property 'configLocation'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'classpath:mybatis/SqlMapConfig.xml' is defined
改为:
7:Eclipse运行项目时巨慢老卡
将Eclipse的配置文件eclipse.ini修改参数为2048m
8:
找不到mapper映射文件
或者
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey
使用mybatis逆向工程生成的mapper.xml文件没有进入war包中
修改:
在taotao-manage-mapper 的pom文件中配置,使得自动将mapper.xml文件放入war包中
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
9:Controller类可以声明为private 吗
可以,不会影响程序运行结果
10:jsp页面中的方法无法进行跳转
if(pid!=undefined && pid!="" && pid!="null"){
var postData = {
pid:pid, pname: encodeURI(MainTitle), ptid: typeId, plid: tags.join(','), pimg: encodeURI(SmallImgPath), poldprice: txtOldPrice,
pnowprice: txtPrice, psort: txtWeight, isStock: IsStock, stock: txtStock, rare: txtFare, pbcount: txtBrowseCount, issellwell: IsSellWell, isrecommend: IsRecommend, isnew: IsNew, pdetail: encodeURIComponent(NewsDetail)
};
} else {
pname: encodeURI(MainTitle), ptid: typeId, plid: tags.join(','), pimg: encodeURI(SmallImgPath), poldprice: txtOldPrice, pnowprice: txtPrice,
psort: txtWeight, isStock: IsStock, stock: txtStock, rare: txtFare, pbcount: txtBrowseCount, issellwell: IsSellWell, isrecommend: IsRecommend, isnew: IsNew, pdetail: encodeURIComponent(NewsDetail)
}
else中的数据格式不对
else {
var postData = {
pname: encodeURI(MainTitle), ptid: typeId, plid: tags.join(','), pimg: encodeURI(SmallImgPath), poldprice: txtOldPrice, pnowprice: txtPrice,
psort: txtWeight, isStock: IsStock, stock: txtStock, rare: txtFare, pbcount: txtBrowseCount, issellwell: IsSellWell, isrecommend: IsRecommend, isnew: IsNew, pdetail: encodeURIComponent(NewsDetail)
}
}
11:js无法跨域访问出现的问题
12:无法找到页面404错误,需要在url中加入项目名或者../
13:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.honszeal.project.zcld_hxzs.service.ProductService com.honszeal.project.zcld_hxzs.controller.ProductController.productService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.honszeal.project.zcld_hxzs.dao.ProductDao com.honszeal.project.zcld_hxzs.service.impl.ProductServiceImpl.productDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.honszeal.project.zcld_hxzs.dao.ProductDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
错误代码块:
package com.honszeal.project.zcld_hxzs.dao;
public class ProductDao {
}
原因:ProductDao 应该是一个接口而不能是类
package com.honszeal.project.zcld_hxzs.dao;
public interface ProductDao {
}
13:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘indexController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.taotao.portal.service.ContentService com.taotao.portal.controller.IndexController.contentService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.taotao.portal.service.ContentService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
分析:可能配置文件出错
配置文件:
<!-- 扫描包,加载service实现类 -->
<context:component-scan base-package="com.taotao.portal.service"></context:component-scan>
将其改为com.taotao.portal.serviceImpl就好了
分析原因:
如上如果配置文件中写com.taotao.portal.service实无法加载com.taotao.portal.serviceImpl下面的类的
所以修改如下
配置文件
<!-- 扫描包,加载service实现类 -->
<context:component-scan base-package="com.taotao.portal.service"></context:component-scan>
包路径
13:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.taotao.search.dao.SearchDao com.taotao.search.service.impl.SearchServiceImpl.searchDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.taotao.search.dao.SearchDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
包没有扫描上
错误代码块
<!-- 扫描包,加载service实现类 -->
<context:component-scan base-package="com.taotao.search.service"></context:component-scan>
改正:
不扫描controller的原因是父子容器的问题
<!-- 扫描包,加载service实现类 -->
<context:component-scan base-package="com.taotao.search">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
**@Repository**
public class SearchDaoImpl implements SearchDao {
@Autowired
private SolrServer solrServer;
14:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.honszeal.project.zcld_hxzs.dao.ProductDao.showChildType'. It's likely that neither a Result Type nor a Result Map was specified.
错误代码块
<!-- 子级商品分类修改回显-->
<select id="showChildType" parameterType="ProductType" >
SELECT tt.*,
(SELECT tt1.GoodsTypeName FROM tb_e_g_goods_type tt1 WHERE tt1.goodsTypeId = tt.FGTID) AS parentTypeName
FROM tb_e_g_goods_type tt WHERE tt.GoodsTypeID=#{goodsTypeID};
</select>
这是一个select但是没有返回值
改正:
<!-- 子级商品分类修改回显-->
<select id="showChildType" parameterType="ProductType" resultType="ProductType" >
SELECT tt.*,
(SELECT tt1.GoodsTypeName FROM tb_e_g_goods_type tt1 WHERE tt1.goodsTypeId = tt.FGTID) AS parentTypeName
FROM tb_e_g_goods_type tt WHERE tt.GoodsTypeID=#{goodsTypeID};
</select>
15:参数传递问题
<table class="easyui-datagrid" id="contentList" data-options="toolbar:contentListToolbar,singleSelect:false,collapsible:true,pagination:true,method:'get',pageSize:20,url:'/content/query/list',queryParams:{categoryId:0}">
此时
/**
* 查询内容列表并分页
*/
@RequestMapping("/query/list")
@ResponseBody
public EUDataGridResult categoryList(Integer page,Integer rows,Long queryParams){
EUDataGridResult result = contentService.categoryList(page,rows,queryParams);
return result;
}
参数传递错误,类似于js中的这个代码块
var pram = {
type: 'GetImgChange',
pageIndex: PageIndex,
Likethis: likethis
};
此时后台controller的参数应该是type,pageIndex,Likethis而不是pram
故修改为
/**
* 查询内容列表并分页
*/
@RequestMapping("/query/list")
@ResponseBody
public EUDataGridResult categoryList(Integer page,Integer rows,Long categoryId){
EUDataGridResult result = contentService.categoryList(page,rows,categoryId);
return result;
}
16:406错误
/**
* 测试post请求
*/
@RequestMapping(value="/httpclient/post",method=RequestMethod.POST)
@ResponseBody
public TaotaoResult testPost(String username,String password){
String result = "username:"+username+",password:"+password;
System.out.println(result);
return TaotaoResult.ok();
}
@Test
public void doPost() throws Exception{
//创建一个httpclient对象,相当于一个浏览器
CloseableHttpClient httpClient = HttpClients.createDefault();
//创建一个post对象,*.html才会被拦截
HttpPost post = new HttpPost("http://localhost:8082/httpclient/post.html");
//执行post请求
CloseableHttpResponse response = httpClient.execute(post);
String string = EntityUtils.toString(response.getEntity());
System.out.println(string);
response.close();
httpClient.close();
}
<html><head><title>Apache Tomcat/7.0.47 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 406 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.47</h3></body></html>
查看jackson包是否存在
如果存在看后缀是否是html,如果是html是不能响应json数据的,需要修改后缀名
在web-xml配置文件中添加
17:post提交乱码
/**
* 测试post请求
*/
@RequestMapping(value="/httpclient/post",method=RequestMethod.POST)
@ResponseBody
public String testPost(String username,String password){
return "username:"+username+",password:"+password;
}
@Test
public void doPostWithParam() throws Exception{
//创建一个httpclient对象,相当于一个浏览器
CloseableHttpClient httpClient = HttpClients.createDefault();
//创建一个post对象,*.html才会被拦截
HttpPost post = new HttpPost("http://localhost:8082/httpclient/post.html");
//创建一个Entity,模拟一个表单
List<NameValuePair> kvlist = new ArrayList<>();
kvlist.add(new BasicNameValuePair("username", "张三"));
kvlist.add(new BasicNameValuePair("password", "123"));
//包装成一个Entity对象
StringEntity entity = new UrlEncodedFormEntity(kvlist, "utf-8");
//设置请求的内容
post.setEntity(entity);
//执行post请求
CloseableHttpResponse response = httpClient.execute(post);
String string = EntityUtils.toString(response.getEntity());
System.out.println(string);
response.close();
httpClient.close();
}
但是portal控制台不是乱码,即控制台提交的时候,服务端接收的时候并没有乱码,是响应给客户端的时候显示乱码,响应乱码,在controller中添加,produces=MediaType.TEXT_PLAIN_VALUE+”;charset=utf-8”),并且使用.action后缀,否则会406
修改:
/**
* 测试post请求
*/
@RequestMapping(value="/httpclient/post",method=RequestMethod.POST,produces=MediaType.TEXT_PLAIN_VALUE+";charset=utf-8")
@ResponseBody
public String testPost(String username,String password){
return "username:"+username+",password:"+password;
}
运行结果展示:
18:
错误提示
org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [classpath:spring/applicationContext*.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist
没有将配置文件加载到class下
原因展示
这段代码本意是想让XXXMapper.xml文件也加载到classes文件下,但是只加载了src/main/java下的
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
修改
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
编译成功之后展示
19:
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: ERROR: [doc=536563] Error adding field 'item_price'='2.99E7' msg=For input string: "2.99E7"
at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:552)
原因分析
改正:
//商品价格
private long price;
20:
java.lang.IllegalStateException: Optional int parameter 'page' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
public String search(@RequestParam(value="q",defaultValue="手机")String queryString,int page,Model model){
SearchResult searchResult = searchService.search(queryString, page);
改正:
public String search(@RequestParam(value="q",defaultValue="手机")String queryString,Integer page,Model model){
SearchResult searchResult = searchService.search(queryString, page);
21:空指针异常
@RequestMapping("/search")
public String search(@RequestParam(value="q",defaultValue="手机")String queryString,Integer page,Model model){
SearchResult searchResult = searchService.search(queryString, page);
//向页面传递参数
此时page刚开始为空,为null,下面是serviceImpl代码
public interface SearchService {
SearchResult search(String queryString,int page);
}
将null赋值给int类型,报错
改正:
public String search(@RequestParam(value="q",defaultValue="手机")String queryString,
@RequestParam(defaultValue="1")Integer page,Model model){