开始springboot
jsp页面热部署相关:
- springboot application.yml配置
server:
port: 9898
servlet:
context-path: /user
jsp:
init-parameters:
development: ture
- 需要导入的依赖
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
- 还需要的配置
- ok热部署相关配置完毕!
mybatis的Dao层的映射文件中的错
- 模糊查询
<select id="queryCount" resultType="Int">
<bind name="value" value="'%'+value+'%'"/>
select count(*) from test.t_user where ${column} like #{value}
</select>
这里 column字段 想根据属性模糊查询 如果使用#{column},
例:查询name属性中含有李的数据
系统编译成的sql语句为
select count(*) from t_user where 'name' like %李%
最后返回为0 查询不到 它把属性转成了字符串
而使用${} sql为
select count(*) from t_user where name like %李%
这样结果就正确了
这里还用到里bind标签 dao的接口参数用@param声明例:
@Param(value = "column") String column
就能使用bind标签给参数加一点东西,用在模糊查询上刚刚好
二级缓存
直接在mybatis里的mapping文件中加一个标签
<cache/>
就开启了mybatis自己的缓存
测试:如何测试缓存是否开启
- 将日志文件设置成debug模式
- 使用相同的sql语句查询两次及以上
- 在日志文件中会有 Cache Hit Ratio
- 在使用增删改操作时会清空缓存
restful风格相关
@PostMapping(value = "/addUser")
public User addUser(@RequestBody User user,@RequestParam(value = "multipartFile", required = false)MultipartFile multipartFile) throws IOException {
iUserService.saveUser(user);
return user;
}
这里有四种注解
@PostMapping @PutMapping @DeleteMapping @GetMapping
对应着这几种情况:GET⽤来获取资源,POST⽤来添加资源(也可以⽤于更新资源),PUT⽤来更新资源,DELETE⽤来删除资源。
@RequestParam参数前的注解表示接收的是一个值
@RequestBody 表示接收的为一个json对象
其中这两个参数注解中有4个参数
- name:给接收到的参数起别名
- value:请求绑定的参数名
- required:该值是否可以为空
- defaultValue:如果请求中没有携带该参数时,该参数的默认值