1. 程式人生 > 其它 >小程式無法保持Session的問題

小程式無法保持Session的問題

pom.xml

<dependencies>
    <!--mybatis-spring-boot-starter: 整合-->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.1</version>
    </dependency>
    <!--官方的-->
    <!--jdbc-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <!--mysql-->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

application.properties

spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/song?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# 整合mybatis
mybatis.type-aliases-package=com.song.pojo
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

UserMapper

// 這個註解表示了這是一個mybatis的mapper類
@Mapper
@Repository
public interface UserMapper {
    List<User> queryUserList();
    User queryUserById();
    int addUser(User user);
    int updateUser(User user);
    int deleteUser(int id);
}

UserMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.song.mapper.UserMapper">
    <select id="queryUserList" resultType="user">
        select * from songyuming.user
    </select>
    <select id="queryUserById" resultType="user">
        select * from songyuming.user where id=#{id}
    </select>
    <insert id="addUser" parameterType="user">
        insert into songyuming.user (id,name,pwd)
        values (#{id},#{name},#{pwd})
    </insert>
    <update id="updateUser" parameterType="user">
        update songyuming.user set name=#{name},pwd=#{pwd}
        where id=#{id}
    </update>
    <delete id="deleteUser" parameterType="int">
        delete from songyuming.user where id=#{id}
    </delete>
</mapper>