从零学习springboot(四)--整合mybtais

1、集成mybatis starter

<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->

<dependency>

<groupId>org.mybatis.spring.boot</groupId>

<artifactId>mybatis-spring-boot-starter</artifactId>

<version>1.3.2</version>

</dependency>

2、加入数据库驱动(mysql)

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

</dependency>

3、在application.properties 中添加数据库以及实体对象包信息

## mybatis config info

mybatis.type-aliases-package=com.linkus.uac.dao.po

## datasource config info

spring.datasource.driverClassName = com.mysql.jdbc.Driver

spring.datasource.url = jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8

spring.datasource.username = root

spring.datasource.password = 123qwe!@#

4、配置mapper接口位置信息

@SpringBootApplication

@MapperScan("club.isource.dao.mapper")

public class App

{

public static void main( String[] args )

{

SpringApplication.run(App.class, args);

}

}

5、测试

1)建立实体对象UserPo

private String userid;

 

private String username;

 

private String uuid;

 

private String password;

 

private Date lastedloginat;

 

private String lastedloginip;

 

private String isdeleted;

 

private String isuse;

 

private String idcard;

 

private String xm;

 

private String xb;

 

private String email;

 

private String telephone;

 

private Date createtime;

 

private String deptcode;

 

private String gh;

 

private String ereacode;

 

private String parentcode;

 

private String usertype;

 

private String picid;

2)建立测试接口UserInf

public interface UserInf {

UserPo selectUserByKey(String userid);

}

3)建立xml映射文件UserInf

<?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="club.isource.dao.mapper.UserInf" >

<resultMap id="BaseResultMap" type="club.isource.dao.mapper.po.UserPo" >

<id column="USERID" property="userid" jdbcType="VARCHAR" />

<result column="USERNAME" property="username" jdbcType="VARCHAR" />

<result column="UUID" property="uuid" jdbcType="VARCHAR" />

<result column="PASSWORD" property="password" jdbcType="VARCHAR" />

<result column="LASTEDLOGINAT" property="lastedloginat" jdbcType="DATE" />

<result column="LASTEDLOGINIP" property="lastedloginip" jdbcType="VARCHAR" />

<result column="ISDELETED" property="isdeleted" jdbcType="VARCHAR" />

<result column="isuse" property="isuse" jdbcType="VARCHAR" />

<result column="IDCARD" property="idcard" jdbcType="VARCHAR" />

<result column="xm" property="xm" jdbcType="VARCHAR" />

<result column="xb" property="xb" jdbcType="VARCHAR" />

<result column="EMAIL" property="email" jdbcType="VARCHAR" />

<result column="TELEPHONE" property="telephone" jdbcType="VARCHAR" />

<result column="CREATETIME" property="createtime" jdbcType="DATE" />

<result column="DEPTCODE" property="deptcode" jdbcType="VARCHAR" />

<result column="gh" property="gh" jdbcType="VARCHAR" />

<result column="ereacode" property="ereacode" jdbcType="VARCHAR" />

<result column="parentcode" property="parentcode" jdbcType="VARCHAR" />

<result column="usertype" property="usertype" jdbcType="VARCHAR" />

<result column="picid" property="picid" jdbcType="VARCHAR" />

</resultMap>

 

<sql id="Base_Column_List" >

USERID, USERNAME, UUID, PASSWORD, LASTEDLOGINAT, LASTEDLOGINIP, ISDELETED, isuse,

IDCARD, xm, xb, EMAIL, TELEPHONE, CREATETIME, DEPTCODE, gh, ereacode, parentcode,

usertype, picid

</sql>

<select id="selectUserByKey" resultMap="BaseResultMap" parameterType="java.lang.String">

select

<include refid="Base_Column_List" />

from fw_user

where USERID = #{userid,jdbcType=VARCHAR}

</select>

</select>

</mapper>

4)

 

The server time zone value '?й???????' is unrecognized or represents more than one time zone.

使用新版本的mysql驱动发生错误

解决方法:在jdbc url上加入serverTimezone=UTC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Springboot CAS-Client 是一个基于Springboot框架集成CAS(Central Authentication Service)的客户端。 CAS是一种单点登录(Single Sign-On)协议,它允许用户在一次登录后就能够访问多个应用,而无需重新认证。 Springboot CAS-Client 的作用是充当CAS服务端和应用系统之间的中间件,它负责向CAS服务端发送认证请求,并根据认证结果来管理用户的登录状态。 为了集成CAS,我们首先需要在Springboot项目中引入相应的依赖,例如spring-boot-starter-web和spring-boot-starter-security。接着,我们需要配置CAS服务端的地址信息,包括CAS服务端的登录URL、登出URL以及验证票据的URL等。 在Springboot CAS-Client中,我们也可以自定义一些过滤器和拦截器来实现相关的功能。例如,我们可以编写一个CAS认证过滤器来拦截所有的请求,并判断用户的登录状态。如果用户未登录,则跳转到CAS服务端进行认证;如果用户已登录,则直接放行请求。此外,我们还可以编写一个CAS登出拦截器来处理用户的登出请求,并在登出完成后将用户重定向到指定的页面。 总的来说,Springboot CAS-Client 提供了一个简洁、灵活的方式来集成CAS协议,使得我们的Springboot应用能够享受到单点登录带来的便利。通过它,我们可以轻松地实现用户认证、登录状态管理以及注销等功能,提升用户体验并提高开发效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值