标签:rri request zone int demo 扫描 mysqld rest osi
SpringWeb,JDBC API, MybatisFramework, MysqlDriver
将 application.properties改为application.yml(使用更简洁), application.yml文件内容如下:
server:
port: 8081
?
spring:
datasource:
username: root
password: root
url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
?
mybatis:
mapper-locations: classpath:mapping/*Mapper.xml
type-aliases-package: com.example.entity.demo
logging:
level:
com:
example:
mapper : debug
在build中配置resources,来防止我们资源导出失败的问题-->
<build>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.properties
**/*.xmlinclude>
includes>
<filtering>truefiltering>
resource>
<resource>
<directory>src/main/javadirectory>
<includes>
<include>**/*.properties
**/*.xmlinclude>
includes>
<filtering>truefiltering>
resource>
resources>
build>
controller包UserController类, entity包User类, mapper包UserMapper(interfac接口), service包UserService类,mapping包UserMapping.xml
实体类User类里声明变量,有参构造,Set()、Get()方法, 以及toString()
package com.example.demo.mapper;
import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
?
import java.util.List;
?
/**
* @author x
* @Date 2021/05/24
*/
<?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.example.demo.mapper.UserMapper">
?
<resultMap id="BaseResultMap" type="com.example.demo.entity.User">
<result column="id" jdbcType="INTEGER" property="id"/>
<result column="userName" jdbcType="VARCHAR" property="username"/>
<result column="passWord" jdbcType="VARCHAR" property="password"/>
<result column="realName" jdbcType="VARCHAR" property="address"/>
resultMap>
<select id="getAll" resultType="com.example.demo.entity.User">
select * from user
select>
<select id="Sel" resultType="com.example.demo.entity.User">
select * from user where 1=1
<if test="user.id != null">
AND id = #{user.id}
if>
select>
<insert id="Add" parameterType="com.example.demo.entity.User">
INSERT INTO user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="user.username != null">
username,
if>
<if test="user.password != null">
password,
if>
<if test="user.address != null">
address,
if>
trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="user.username != null">
#{user.username,jdbcType=VARCHAR},
if