三表多表查询
左连接
太常见了
数据量如果过大导致查询速度不及预期(4、5秒之内)应当优化
.code,u.username, c.*
from ad_call_record r
left join lego_user.user u on r.user_id = u.id
left join ad_callback_content c on r.ref_id = c.id
理解Spring原始注解
@Component 通用
@Controller 在web层
@Service 在Service
@Repository 在dao层
@Repository(value=“userDao”)
该注解是告诉Spring,让Spring创建一个名字叫“userDao”的UserDaoImpl实例。
当Service需要使用Spring创建的名字叫“userDao”的UserDaoImpl实例时,就可以使用@Resource(name = “userDao”)注解告诉Spring,Spring把创建好的userDao注入给Service即可。
@RestController与@RequestMapping区别
这四个为一组
@Autowired 自动注入 默认是数据类型注入
@Qualifier(“userDao1”)+自动注入,按名称来注入
@Resource(name=“userDao1”)========@Autowired+@Qualifier(“userDao1”)
@Value 普通类型注入 应用场景:
@Value(“${jdbc.driver}”)
private String driver;
@Scope (“prototype”) singleton常用的两个取值
新注解:补充,在ssm中用的可能不多,到以后springboot一定是常用的,实现注解取代配置的效果
@Configuration 用于指定当前类是一个Spring配置类,当创建容器是会从该类上加载注解
@ComponentScan(“com.study”)
====>
@Bean
标注将该方法的返回值存储到Spring容器中
@PropertySource
=====>
@Import
导入其他配置类
@Import(DatasourceConfiguration.class)
常用注解总结
一级:频繁常用
@RequestMapping
@GetMapping
@PostMapping
@RestController
@Service
@Mapper
@Repository
@Slf4j
@Compent
@ResponseBody
@PathVariable
@RequestParam
@Bean
@Before
@After
@Transactional
@Configuration
@Resource
@Autowired
@SpringBootApplication
@SpringBootTest
@Test
@Override
@Value
二级:经常用
@PutMapping
@DeleteMapping
@MapperScan
三级:一般用
@Import 引用
@CofigurationProperties
@EnableConfiguratioProperties
四级:很少用
@Mapping
索引mysql
//索引:就像查目录一样提高查询速度。但是对update/delete/insert效率会有影响
/**
* @Description:
* @author: samxie
* @date: 2022/6/6
* @param args
* @return: void
* 索引----》二分查找 没有使用索引的时候select * from … where id = …全局扫描表,速度很慢。
* 类型:
* 主键索引,Primary key
* 唯一索引unique
* 普通索引 index
* 全文索引 fulltext 适用于myisam
* 开发中考虑用全文搜索Solr 和ElasticSearch
*
* 如果某列值不会重复的,则优先使用唯一索引unique
* 频繁查询where的字段适合用索引,但是频繁增删改的字段不合适用索引。
* 唯一性太差了不适合做索引,比如性别1 2等
*/
create table index_test (
id int,
`name` varchar(32)
);
show indexes from index_test;
#唯一索引
create unique index id_index on index_test (id);
#添加普通索引
create index id_index2 on index_test (id);
#添加普通索引2
alter table index_test add index id_index3(id);
#添加主键索引
alter table index_test add primary key (id);
#删除索引
drop index id_index on index_test;
#删除主键索引
alter table index_test drop primary key ;