Illegal modifier for parameter userMapper; only final is permitted

Posted chen1919

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Illegal modifier for parameter userMapper; only final is permitted相关的知识,希望对你有一定的参考价值。

报错的原因是

 1 package com.chen.service.impl;
 2 
 3 import java.io.IOException;
 4 import java.io.InputStream;
 5 
 6 import org.apache.catalina.User;
 7 import org.apache.ibatis.io.Resources;
 8 import org.apache.ibatis.session.SqlSession;
 9 import org.apache.ibatis.session.SqlSessionFactory;
10 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
11 import org.springframework.context.ApplicationContext;
12 import org.springframework.context.support.ClassPathXmlApplicationContext;
13 
14 import com.chen.mapper.UserMapper;
15 import com.chen.service.UserService;
16 
17 public class UserServiceImpl implements UserService{
18 
19     
20     //声明mapper变量
21     private UserMapper userMapper;//这行代码如果要加private修饰的话,就不能放在下面的代码中
22     public User userLoginService(String uname, String pwd) throws IOException {
23 
24         //获取sqlsession对象
25 /*        InputStream is = Resources.getResourceAsStream("MyBatis.xml");
26         SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
27         SqlSession ss = factory.openSession();
28         //获取Mapper接口实例化对象
29         UserMapper um=ss.getMapper(UserMapper.class);*/
30         //当我们在applicationcontext中配置好mybatis后,就不用再像上面一样进行方法调用,获取实例化对象
31         
32         //获取spring容器对象
33 /*        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationcontext.xml");
34         UserMapper um = (UserMapper) ac.getBean("userMapper");//mapper实例化接口的类名首字母小写即是Bean id
35         已经在servlet获取过一次spring容器对象了,所以我们没必要再获取一次
36         */
37         //操作数据库
38         return (User) userMapper.selUser(uname, pwd);
39     }
40 
41 }

在java语法里,方法的形参以及方法体中的变量都是局部变量,不能使用访问权限修饰符public,private,protected。把Reader()方法里的所有访问权限修饰符private删除或换成final就可以。

以上是关于Illegal modifier for parameter userMapper; only final is permitted的主要内容,如果未能解决你的问题,请参考以下文章

解决 Illegal DefaultValue null for parameter type integer 异常

swagger2 Illegal DefaultValue null for parameter type integer

错误之Illegal mix of collations for operation 'like'

MySQL Error: Illegal mix of collations for operation 'concat'

URLDecoder: Illegal hex characters in escape (%) pattern - For input string

xcode运行项目报error: Illegal Configuration: Compiling IB documents for earlier than iOS 7