@ControllerAdvice
public class GlobalExceptionHandler {
/**
* 拦截运行异常出现的错误~~~
*/
(RuntimeException.class)
public Map<Object, Object> exceptionHandler() {
Map<Object, Object> map = new HashMap<>();
map.put("error", "500");
map.put("msg", "系统出现错误~");
return map;
}
}
@ExceptionHandler(RuntimeException.class)
@SpringBootApplication
//@EnableAutoConfiguration 启动依赖jar包中的 类 比如 SpringMVC、Spring
//@ComponentScan("com.api.controller")
Mybatis 的配置信息:
application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/test
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
("com.mapper")
public class SpringMybatis {
public static void main(String[] args) {
SpringApplication.run(SpringMybatis.class);
}
}
public interface UserMapper {
// xml 注解
@Select("SELECT * FROM USERS WHERE NAME = #{name}")
UserEntity findByName(@Param("name") String name);
@Insert("INSERT INTO USERS(NAME, AGE) VALUES(#{name}, #{age})")
int insert(@Param("name") String name, @Param("age") Integer age);
}