maven项目常见问题


1.

Java compiler level does not match the version of the installed Java project facet. Shiyan3  Unknown Faceted Project Problem (Java Version Mismatch)
解决:以JDK1.8为例

(1)eclipse窗口-->windows-->Preferences-->java-->Compiler

(2)项目右键-->Properties-->java Compiler-->将Use compliance from ...前的勾去掉

(3)项目右键—>Properties—>Project Facets—>java选择1.8


2.

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
解决:

(1)在pom.xml中加入依赖包
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.10.0</version>
 </dependency>
 <dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.10.0</version>
 </dependency>

(2)在src/main/resources包下新建log4j2.xml文件,写入(resources包中文件编译完后会放入classpath):
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%m%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

3.

org.hibernate.hql.internal.ast.QuerySyntaxException: ### is not mapped

这个异常是hql语句写错了,hibernate中的hql不是sql,区别在于from后面的表名不是数据库中的表名,是实体类名字

如:

public List<Voucher> getAll(){
        String hql=
"from voucher";//应该写成String hql="from Voucher";
        Query query=sessionFactory.getCurrentSession().createQuery(hql);
       
return query.list();
    }
4.

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
  • 1
具体解决方法请看:
https://www.cnblogs.com/djoker/p/6443978.html

5.hql查询多条记录,结果都是重复第一条记录

出现这种情况是因为查询的条件字段为主键,并且该主键设置为可重复,例如:

数据库表:
数据库图
当cid为该表的主键且hql查询语句为如下时

hql = "select sid from sc s where s.cid = 1"
  • 1

查询出来的结果就会被第一条覆盖,结果为三条10001

5.在Action中出现method is not allowed!的错误

是因为在Struts 2.5中为了安全设置的,默认情况下,没有允许的方法名是不能提供直接执行的。

有两种做法:

(1)针对Action,在xml中配置<allowed-methods>regex:.*</allowed-methods>,允许所有。或者配置<allowed-methods>login,logout,find</allowed-methods>,仅允许特定名字列表的方法被执行。在注解版中,这个配置等价于:@AllowedMethods("regex:.*")

(2)在package中添加global-allowed-methods,设置该package下所有action允许的方法列表。

参考:

http://blog.sina.com.cn/s/blog_45ef2e490102ye10.html

https://blog.csdn.net/qq_29407009/article/details/51474118

https://ask.csdn.net/questions/260958


 <package name="default" extends="struts-default" namespace="/">
   
<!-- 关键地方  struts2.5 为了提升安全性,添加了 allomethod 这么个玩意-->
    
<global-allowed-methods>regex:.*</global-allowed-methods>
       
<action name="login*" class="com.maobo.action.LoginAction" method="{1}">
           
<result name="ok">/WEB-INF/page/success.jsp</result>
           
<result name="error">/WEB-INF/page/error.jsp</result>
       
</action>
   
</package>

6.struts中顺序

              result-types
    interceptors
    default-interceptor-ref
    default-action-ref
    default-class-ref
    global-results
    global-exception-mappings
       action*
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值