Mybatis mapper using @SessionScope error

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Mybatis mapper using @SessionScope error

翁正航
I have a SpringBoot application and run with mybatis

here is the mapper 

```java
 @Component
    @Mapper
    public interface AccountMapper {
        @Insert("insert into dc_account(identification,nickname,username,password) values (#{identification},#{nickname},#{username},#{password})")
        public int insert(Account account);
        @Update("update dc_account set identification=#{identification},nickname=#{nickname},username=#{username},password=#{password}")
        public int update(Account account);

        @Select("select * from dc_account where username=#{username} and password=#{password}")
        @Results(
            id = "account",
            value = {
                @Result(property = "identification", column = "identification"),
                @Result(property = "nickname", column = "nickname"),
                @Result(property = "username", column = "username"),
                @Result(property = "password", column = "password")   
            }
        )
        Account select(Account account);
    }

```

Account class

```java
@Component
@SessionScope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Account{
    @Value("1")
    int identification;
    @Value("1")
    String nickname;
    @Value("1")
    String username;
    @Value("1")
    String password;
//getter and setter
}
```

Controller

```java
@Autowired
AccountMapper accountMapper;
@Autowired
Account account;
//.......
@RequestMapping("/login")
    Account login(
        @RequestParam("username")String username,
        @RequestParam("password")String password){
            account.setUsername(username);
            account.setPassword(password);
            accountMapper.select(account);
            return account;
    }

```
and when i enter localhost:8080/login?username=1&password=1

it report error message of 
enter image description here

But if i remove the @SessionScope annotation of Account class, everything works fine.

Why is causing this problem?Can anyone give me some advice?



--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/a06844a7-e241-45ed-b416-b254b40366fb%40googlegroups.com.