springboot关于mybatis的mapper.xml文件问题

例如有建一张user表

create table user(
id bigint auto_increment prmary key,
username varchar(50) not null,
password varchar(50) not null
)

实体类

Class User implements Serializable{
	private long id;
	private String username;
	private String password;
	//省略get set方法
}
  1. java注解形式
    springboot整合mybatis网上教程很多省略
    UserMapper.java根据id查询用户信息
@Select(select username,password from user where id=(#{id}))
User selectById(long id);

mapper文件写完后只需在springboot里添加一个扫描注解。

@MapperScan("cy.cms.application.dx.mapper")
@SpringBootApplication
public class Application {
public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

优点:简单快速不需要写xml注解
缺点:sql语句过长

  1. xml文件形式
    使用****生成所需要的mapper.java mapper.xml以及pojo导入springboot项目中,在springboot的配置文件添加
mybatis.mapper-locations= classpath:mapper/*.xml!

项目内容
springboot关于mybatis的mapper.xml文件问题

相关文章:

  • 2022-12-23
  • 2022-03-03
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2023-01-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2021-10-01
  • 2021-09-09
  • 2022-01-21
  • 2022-12-23
  • 2022-03-02
相关资源
相似解决方案