毕业实习项目技术学习笔记
参考文献
学习视频
2小时学会Spring Boot:https://www.imooc.com/learn/767
学习资料
SpringBoot入门:https://blog.csdn.net/Phapha1996/article/details/78515865
【推荐】Spring boot <一>入门篇:https://www.cnblogs.com/ityouknow/p/5662753.html
Spring Boot中文官方文档:https://www.breakyizhan.com/springboot/3028.html
SpringBoot—访问关系型数据库—SpringData JPA:https://blog.csdn.net/phapha1996/article/details/78712597
【推荐】Spring Boot 参考指南(翻译中):
http://oopsguy.com/documents/springboot-docs/1.5.4/index.html#boot-features-spring-mvc
【推荐】Spring Boot + Jpa(Hibernate) 架构基本配置:
https://blog.csdn.net/javahighness/article/details/53055149
属性配置
spring.datasource.url:jdbc:mysql://127.0.0.1:3306
spring.datasource.username:root
spring.datasource.password:123456
spring.datasource.driver-class-name:com.mysql.jdbc
配置文件
目录:(src/main/resources)
application.properties:(src/main/resources)
server.port:8081
server.context-path:/projectname
application.yml:
server: port: 8080 context-path: /demo tomcat: uri-encoding: UTF-8 spring: datasource: url : jdbc:mysql://xxxx:3306/xxxxx username : xxxx password : xxxxx driverClassName : com.mysql.jdbc.Driver jpa: database : MYSQL show-sql : true hibernate: ddl-auto : update naming-strategy : org.hibernate.cfg.ImprovedNamingStrategy properties: hibernate: dialect : org.hibernate.dialect.MySQL5Dialect
注解
@Controller //处理http请求,默认返回resources/templates下的html模板(view),返回参数为String类型。
@RequestMapping("/users")
public class XX{
}
@RestConroller //Spring4之后新加的注解,原来返回json需要@ResponseBody配合@Controller
public class XXX{
@Autowired
private GirlProperties girlProperties;
}
@Value("${cupSize}")
private String cupSize;
@RequestMapping(value="/user/", method=RequestMethod.GET) //配置URL映射
public String say(){
return cupSize;
}
@Component
@ConfigurationProperties(prefix="girl")
public class GirlProperties{
private String cupSize;
public String getCupSize(){
return cupSize;
}
}
Controller的使用
@PathVariable:获取url中的数据
@RequestParam:获取请求参数的值,属性有value,required,defaultValue
@GetMapping:组合注解Get
@PostMapping:组合注解Post
===========================================
【数据库】
Spring-Data-Jpa
JPA:Java Persistence API,定义了一系列对象持久化的标准,实现规范的产品有:Hibernate、TopLink等
@Entity
public class Girl{
@Id
@GenerateValue //自增
private Integer id;
private String cupSize;
//setter or getter methods
}
@Transactional //添加事务