形参实参,参数传递的是值,与名字无关
只有一个数据,按下标取值,名字任意(但是要注意开发规范)
代理对象 常见代理方式 1.JDK动态代理2.CGLIB动态代理JDK默认提供
要求被代理者必须实现(有)接口,代理对象是目标对象的实现类/兄弟元素
Mapper接口说明没有接口也可以创建代理对象,代理对象是目标对象的子类(继承)
需要手动导入jar包
spring自身添加cglib的依赖
获取的mapper接口对象并不是接口的对象,因为接口不能实例化,所以此对象是JDK动态代理生成的代理对象!!
说明是JDK生成的代理对象↑
三大框架整合 1.Spring框架将复杂的第三方框架整合,使程序→控制→调用浑然一体,以一种统一的方式调用
核心:
IOC-DIIOC:控制反转,无需自己创建对象,把创建对象的权力交给Spring容器管理,由Spring容器管理对象的生命周期
DI:依赖注入,创建对象时,如果该对象中有需要依赖的属性,Spring为依赖的属性赋值
IOC-DI相辅相成
AOP面向切面编程
2.SpringMVC接收请求,处理请求,返回响应
3.框架之间的调用关系 4.项目整合 创建项目 编辑pom.xml文件编辑核心代码
pojo
package com.jt.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
private Integer id;
private String name;
private Integer age;
private String sex;
}
mapper接口
package com.jt.mapper;
public interface UserMapper {
List findAll();
}
xml映射文件
select * from demo_user
编辑Service接口
package com.jt.service;
import com.jt.pojo.User;
import java.util.List;
public interface UserService {
List findAll();
}
实现类
package com.jt.service;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService{
@Autowired
UserMapper userMapper;
@Override
public List findAll() {
return userMapper.findAll();
}
}
编辑Conrtroller层
package com.jt.controller;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/getUser")
public List findUser(){
return userService.findAll();
}
}
核心配置信息配置 application.yml
#语法: 1.key:(空格)value结构
server:
port: 8090
#整合1.数据源
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
#SpringBoot整合mybatis
mybatis:
#指定别名包
type-aliases-package: com.jt.pojo
#加载指定的xml映射文件
mapper-locations: classpath:/mybatis/mappers
public class SpringbootSsmApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootSsmApplication.class, args);
}
}
Get方法实现参数传递
1.查询id=1的用户数据
controller层代码
package com.jt.controller;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/getUser")
public List findUser(){
return userService.findAll();
}
@GetMapping("findUserById")
public User findUserById(Integer id){
return userService.findUserById(id);
}
}
service
User findUserById(Integer id);
impl实现方法
@Override
public User findUserById(Integer id) {
return userMapper.findUserById(id);
}
mapper层
User findUserById(Integer id);
映射文件
查询:http://localhost:8090/findUserById?id=1
2. 根据name与age查询用户信息
url:..../findUserByNA
3.查询名称以”XXX“结尾的数据



