@PostMapping
public Integer save(@RequestBody User user){
return userMapper.insert(user);
}
选择json格式。以为本人忘记选了415错误,media错误
mybatisx插件
sprinboot yml文件导入xml
mybatis:
mapper-locations: classpath:mapper/*.xml
一直报错
发现重复了
注解和xml都对同样的方法操作了
动态sql
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demos.mapper.UserMapper">
<update id="update">
update sys_user
<set>
<if test="username != null">
username=#{username},
</if>
<if test="nickname != null">
nickname=#{nickname},
</if>
<if test="email != null">
email=#{email},
</if>
<if test="phone != null">
phone=#{phone},
</if>
<if test="address != null">
address=#{address}
</if>
</set>
<where>
id = #{id}
</where>
</update>
</mapper>
@RequestParam
简单一点说作用就是把请求中的指定名称的参数传递给控制器中的形参赋值
@Param
首先明确这个注解是为SQL语句中参数赋值而服务的。
@PathVariable 映射 URL 绑定的占位符
带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义
通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中。
vue跨域放行
package com.example.demos.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class CorsConfig {
// 当前跨域请求最大有效时长。这里默认1天
private static final long MAX_AGE = 24 * 60 * 60;
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
corsConfiguration.setMaxAge(MAX_AGE);
source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置
return new CorsFilter(source);
}
}
成功
vue的created方法不起作用 原来是。目录看错了。