Object Relation MySQL
(1) mybatis启动依赖
完成mybatis对象自动配置,对象放在容器中。
(2) pom.xml文件中指定把src/main/java目录中的xml文件包含到classpath中
(3) 创建实体类
(4) 创建Dao接口
(5) 创建Dao接口对应的mapper文件,xml文件编写sql语句。
(6) 创建Service层对象,调用dao层的方法,完成数据库操作。
api的组织方式。
传统的一个风格: http://localhost:8080/mytrans/addStudent?name=zhangsan&age=20
在地址上提供了访问的资源名称addStudent,在其之后使用了get方式传递参数。
REST: Representational State Transfer,表现层状态转移。
是一种架构风格和设计理念,并不是标准。
优点: 更简洁,更有层次。
表现层状态转移: 表现层就是视图层,用于显示资源。通过页面显示操作资源的结果。
状态:资源的变化。
转移:资源可以变化的。
一句话描述rest: 使用url表示资源,使用http动作操作资源
GET:查询
post:创建
put:更新
delete:删除资源
注意: rest接口中, 请求方式 + url 一定是惟一的。 否则具有二义性,服务器直接500错误。举例如下:
@GetMapping("/student/{stuId}")
public String queryStudent(@PathVariable(value = "stuId") Integer studentId) {
return "student id is = " + studentId;
}
@GetMapping("/student/{age}")
public String queryStudentByAge(@PathVariable(value = "age") Integer age) {
return "student age is = " + age;
}
从url中获取数据
@GetMapping("/student/{stuId}")
public String queryStudent(@PathVariable(value = "stuId") Integer studentId) {
return "student id is = " + studentId;
}
@GetMapping
: 支持get请求方式,等同于 @RequestMapping(method = RequestMethod.GET)
@PostMapping
: 支持post请求方式,等同于 @RequestMapping(method = RequestMethod.POST)
@PutMapping
: 支持put请求方式,等同于 @RequestMapping(method = RequestMethod.PUT)
@DeleteMapping
: 支持delete请求方式,等同于 @RequestMapping(method = RequestMethod.DELETE)
符合注解,是@Controller和@ResponseBody的组合。
使用 @RestController,当前类中所有的方法都使用了ResponseBody
RedisTemplate
:本质上使用的lettuce
客户端。
StringRedisTemplate :k v都是String ,使用的是String的序列化,可读性好。
RedisTemplate:把k v 经过了序列化存储到redis。 k v是序列化的内容,不能直接识别。默认使用的jdk的序列化机制。
RedisTemplate可以修改序列化器
public String addString(String k, String v) {
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.opsForValue().set(k, v);
}
Dubbo基于RPC协议的一个框架。
(1) 修改pom.xml文件
<build>
<finalName>mybootfinalName>
build>
<packaging>warpackaging>
(2) 主启动类继承SpringBootServletInitializer
将Application类暴露出去,这样可以使用独立的tomcat服务器
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
(3) 部署
将war放在tomcat等服务器的发布目录中。
(1) 修改pom.xml文件
<build>
<finalName>mybootfinalName>
build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>1.4.2-RELEASEversion>
plugin>
plugins>
(2) 执行mave package
war:可以利用真正的容器的能力
jar:方便,不需要使用额外的容器。