欧美企业网站模板,中国建设银行什么是网站用户名,seo推广用什么做网站好,网站建设 力洋网络目录
JdbcTemplate
声明式事务
事务
概述
特性#xff08;ACID#xff09;
编程式事务
声明式事务
基于注解的声明式事务
Transactional注解标识的位置
事务属性#xff1a;只读
事务属性#xff1a;超时
事务属性#xff1a;隔离级别
事务属性#xff1a;传…目录
JdbcTemplate
声明式事务
事务
概述
特性ACID
编程式事务
声明式事务
基于注解的声明式事务
Transactional注解标识的位置
事务属性只读
事务属性超时
事务属性隔离级别
事务属性传播行为
全注解配置事务
基于xml的声明式事务 JdbcTemplate
Spring 框架对 JDBC 进行封装使用 JdbcTemplate 方便实现对数据库操作
搭建子模块spring-jdbc
加入依赖 !--spring jdbc Spring 持久化层支持jar包--dependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion5.2.15.RELEASE/version/dependency
创建jdbc.properties
jdbc.userroot
jdbc.password123456
jdbc.urljdbc:mysql://localhost:3306/spring?characterEncodingutf8useSSLfalse
jdbc.drivercom.mysql.cj.jdbc.Driver
配置文件
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd!--引入外部属性文件创建数据源对象--context:property-placeholder locationclasspath:jdbc.properties/context:property-placeholderbean iddruidDataSource classcom.alibaba.druid.pool.DruidDataSourceproperty nameurl value${jdbc.url}/propertyproperty namedriverClassName value${jdbc.driver}/propertyproperty nameusername value${jdbc.user}/propertyproperty namepassword value${jdbc.password}/property/bean!--创建jdbcTemplate对象注入数据源--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdruidDataSource/property/bean
/beans
准备数据库与测试表
CREATE DATABASE spring;use spring;CREATE TABLE t_emp (id int(11) NOT NULL AUTO_INCREMENT,name varchar(20) DEFAULT NULL COMMENT 姓名,age int(11) DEFAULT NULL COMMENT 年龄,sex varchar(2) DEFAULT NULL COMMENT 性别,PRIMARY KEY (id)
) ENGINEInnoDB DEFAULT CHARSETutf8mb4;
实体类
package com.qcby;public class Emp {private Integer id;private String name;private Integer age;private String sex;public Emp() {}public Emp(Integer id, String name, Integer age, String sex) {this.id id;this.name name;this.age age;this.sex sex;}public Integer getId() {return id;}public void setId(Integer id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex sex;}Overridepublic String toString() {return Emp{ id id , name name \ , age age , sex sex \ };}
}实现CURD
package com.qcby;import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;import java.util.List;SpringJUnitConfig(locations classpath:beans.xml)
public class TestJdbcTemplate {Autowiredprivate JdbcTemplate jdbcTemplate;//添加Testpublic void testInsert(){//1.编写SQL语句String sql insert into t_emp values(NULL,?,?,?);//2.调用jdbcTemplate的方法传入相关参数int rows jdbcTemplate.update(sql, 张三, 20, 男);System.out.println(rows);}//修改Testpublic void testUpdate(){//1.编写SQL语句String sql update t_emp set name? where id?;//2.调用jdbcTemplate的方法传入相关参数int rows jdbcTemplate.update(sql, 李四,1);System.out.println(rows);}//删除Testpublic void testDelete(){//1.编写SQL语句String sql delete from t_emp where id?;//2.调用jdbcTemplate的方法传入相关参数int rows jdbcTemplate.update(sql, 1);System.out.println(rows);}//查询返回单个Testpublic void testSelectObject(){String sql select * from t_emp where id?;Emp emp jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper(Emp.class),2);System.out.println(emp);}//查询返回所有Testpublic void testSelectList(){String sql select * from t_emp;ListEmp list jdbcTemplate.query(sql, new BeanPropertyRowMapper(Emp.class));System.out.println(list);}//查询返回记录总数Testpublic void testSelectValue(){String sql select count(*) from t_emp;Integer count jdbcTemplate.queryForObject(sql, Integer.class);System.out.println(count);}
}声明式事务
事务
概述
数据库事务( transaction)是访问并可能操作各种数据项的一个数据库操作序列这些操作要么全部执行,要么全部不执行是一个不可分割的工作单位。事务由事务开始与事务结束之间执行的全部数据库操作组成
特性ACID
A原子性(Atomicity)
一个事务(transaction)中的所有操作要么全部完成要么全部不完成不会结束在中间某个环节。事务在执行过程中发生错误会被回滚Rollback到事务开始前的状态就像这个事务从来没有执行过一样
C一致性(Consistency)
事务的一致性指的是在一个事务执行之前和执行之后数据库都必须处于一致性状态
如果事务成功地完成那么系统中所有变化将正确地应用系统处于有效状态
如果在事务中出现错误那么系统中的所有变化将自动地回滚系统返回到原始状态
I隔离性(Isolation)
指的是在并发环境中当不同的事务同时操纵相同的数据时每个事务都有各自的完整数据空间。由并发事务所做的修改必须与任何其他并发事务所做的修改隔离。事务查看数据更新时数据所处的状态要么是另一事务修改它之前的状态要么是另一事务修改它之后的状态事务不会查看到中间状态的数据
D持久性(Durability)
指的是只要事务成功结束它对数据库所做的更新就必须保存下来。即使发生系统崩溃重新启动数据库系统后数据库还能恢复到事务成功结束时的状态
编程式事务
事务功能的相关操作全部通过自己编写代码来实现
Connection conn ...;try {// 开启事务关闭事务的自动提交conn.setAutoCommit(false);// 核心操作// 提交事务conn.commit();}catch(Exception e){// 回滚事务conn.rollBack();}finally{// 释放数据库连接conn.close();}
编程式的实现方式存在缺陷
细节没有被屏蔽具体操作过程中所有细节都需要程序员自己来完成比较繁琐代码复用性不高如果没有有效抽取出来每次实现功能都需要自己编写代码代码就没有得到复用
声明式事务
既然事务控制的代码有规律可循代码的结构基本是确定的所以框架就可以将固定模式的代码抽取出来进行相关的封装
封装起来后我们只需要在配置文件中进行简单的配置即可完成操作
好处
提高开发效率消除了冗余的代码框架会综合考虑相关领域中在实际开发环境下有可能遇到的各种问题进行了健壮性、性能等各个方面的优化
所以我们可以总结下面两个概念 编程式自己写代码实现功能 声明式通过配置让框架实现功能
基于注解的声明式事务
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd!--组件扫描--context:component-scan base-packagecom.qcby.tx/context:component-scan!--引入外部属性文件创建数据源对象--context:property-placeholder locationclasspath:jdbc.properties/context:property-placeholderbean iddruidDataSource classcom.alibaba.druid.pool.DruidDataSourceproperty nameurl value${jdbc.url}/propertyproperty namedriverClassName value${jdbc.driver}/propertyproperty nameusername value${jdbc.user}/propertyproperty namepassword value${jdbc.password}/property/bean!--创建jdbcTemplate对象注入数据源--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdruidDataSource/property/bean
/beans
jdbc.userroot
jdbc.password123456
jdbc.urljdbc:mysql://localhost:3306/spring?characterEncodingutf8useSSLfalse
jdbc.drivercom.mysql.cj.jdbc.Driver
创建表
CREATE TABLE t_book (book_id int(11) NOT NULL AUTO_INCREMENT COMMENT 主键,book_name varchar(20) DEFAULT NULL COMMENT 图书名称,price int(11) DEFAULT NULL COMMENT 价格,stock int(10) unsigned DEFAULT NULL COMMENT 库存无符号,PRIMARY KEY (book_id)
) ENGINEInnoDB AUTO_INCREMENT3 DEFAULT CHARSETutf8;
insert into t_book(book_id,book_name,price,stock) values (1,斗破苍穹,80,100),(2,斗罗大陆,50,100);
CREATE TABLE t_user (user_id int(11) NOT NULL AUTO_INCREMENT COMMENT 主键,username varchar(20) DEFAULT NULL COMMENT 用户名,balance int(10) unsigned DEFAULT NULL COMMENT 余额无符号,PRIMARY KEY (user_id)
) ENGINEInnoDB AUTO_INCREMENT2 DEFAULT CHARSETutf8;
insert into t_user(user_id,username,balance) values (1,admin,50);
package com.qcby.tx.controller;import com.qcby.tx.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;Controller
public class BookController {Autowiredprivate BookService bookService;public void buyBook(Integer bookId,Integer userId){bookService.buyBook(bookId,userId);}
}package com.qcby.tx.service;public interface BookService {void buyBook(Integer bookId, Integer userId);
}package com.qcby.tx.service;import com.qcby.tx.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;Service
public class BookServiceImpl implements BookService{Autowiredprivate BookDao bookDao;Overridepublic void buyBook(Integer bookId, Integer userId) {//1.根据图书id查询图书价格Integer price bookDao.getBookPriceByBookId(bookId);//2.更新图书库存-1bookDao.updateStock(bookId);//3.更新用户余额-图书价格bookDao.updateUserBalance(userId,price);}
}package com.qcby.tx.dao;public interface BookDao {Integer getBookPriceByBookId(Integer bookId);void updateStock(Integer bookId);void updateUserBalance(Integer userId, Integer price);
}package com.qcby.tx.dao;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;Repository
public class BookDaoImpl implements BookDao{Autowiredprivate JdbcTemplate jdbcTemplate;Overridepublic Integer getBookPriceByBookId(Integer bookId) {String sql select price from t_book where book_id?;Integer price jdbcTemplate.queryForObject(sql, Integer.class, bookId);return price;}Overridepublic void updateStock(Integer bookId) {String sql update t_book set stockstock-1 where book_id?;jdbcTemplate.update(sql,bookId);}Overridepublic void updateUserBalance(Integer userId, Integer price) {String sql update t_user set balancebalance-? where user_id?;jdbcTemplate.update(sql,price,userId);}
}测试无事务
package com.qcby;import com.qcby.tx.controller.BookController;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;SpringJUnitConfig(locations classpath:beans.xml)
public class TestBook {Autowiredprivate BookController bookController;Testpublic void testBuyBook(){bookController.buyBook(1,1);}
}用户购买图书先查询图书的价格再更新图书的库存和用户的余额
假设用户id为1的用户购买id为1的图书
用户余额为50而图书价格为80
购买图书之后用户的余额为-30数据库中余额字段设置了无符号因此无法将-30插入到余额字段
此时执行sql语句会抛出SQLException
加入事务
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd!--组件扫描--context:component-scan base-packagecom.qcby.tx/context:component-scan!--引入外部属性文件创建数据源对象--context:property-placeholder locationclasspath:jdbc.properties/context:property-placeholderbean iddruidDataSource classcom.alibaba.druid.pool.DruidDataSourceproperty nameurl value${jdbc.url}/propertyproperty namedriverClassName value${jdbc.driver}/propertyproperty nameusername value${jdbc.user}/propertyproperty namepassword value${jdbc.password}/property/bean!--创建jdbcTemplate对象注入数据源--bean idjdbcTemplate classorg.springframework.jdbc.core.JdbcTemplateproperty namedataSource refdruidDataSource/property/beanbean idtransactionManager classorg.springframework.jdbc.datasource.DataSourceTransactionManagerproperty namedataSource refdruidDataSource/property/bean!--开启事务的注解驱动通过注解Transactional所标识的方法或标识的类中所有的方法都会被事务管理器管理事务
--!-- transaction-manager属性的默认值是transactionManager如果事务管理器bean的id正好就是这个默认值则可以省略这个属性 --tx:annotation-driven transaction-managertransactionManager //beans 在BookServiceImpl添加注解Transactional
package com.qcby.tx.service;import com.qcby.tx.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;Transactional
Service
public class BookServiceImpl implements BookService{Autowiredprivate BookDao bookDao;Overridepublic void buyBook(Integer bookId, Integer userId) {//1.根据图书id查询图书价格Integer price bookDao.getBookPriceByBookId(bookId);//2.更新图书库存-1bookDao.updateStock(bookId);//3.更新用户余额-图书价格bookDao.updateUserBalance(userId,price);}
}Transactional注解标识的位置
Transactional标识在方法上则只会影响该方法Transactional标识的类上则会影响类中所有的方法
事务属性只读
设置只读只能查询不能修改、添加、删除
Transactional(readOnly true)
对增删改操作设置只读会抛出下面异常
Caused by: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
事务属性超时
超时回滚释放资源
//超时时间单位秒
Transactional(timeout 3)
执行过程中抛出异常
org.springframework.transaction.TransactionTimedOutException: Transaction timed out
事务属性回滚策略
声明式事务默认只针对运行时异常回滚编译时异常不回滚
可以通过Transactional中相关属性设置回滚策略
rollbackFor属性需要设置一个Class类型的对象rollbackForClassName属性需要设置一个字符串类型的全类名noRollbackFor属性需要设置一个Class类型的对象rollbackFor属性需要设置一个字符串类型的全类名
Transactional(noRollbackFor ArithmeticException.class)
//Transactional(noRollbackForClassName java.lang.ArithmeticException)
事务属性隔离级别
数据库系统必须具有隔离并发运行各个事务的能力使它们不会相互影响避免各种并发问题。一个事务与其他事务隔离的程度称为隔离级别。SQL标准中规定了多种事务隔离级别不同隔离级别对应不同的干扰程度隔离级别越高数据一致性就越好但并发性越弱
隔离级别一共有四种 读未提交READ UNCOMMITTED 允许Transaction01读取Transaction02未提交的修改 读已提交READ COMMITTED、 要求Transaction01只能读取Transaction02已提交的修改 可重复读REPEATABLE READ 确保Transaction01可以多次从一个字段中读取到相同的值即Transaction01执行期间禁止其它事务对这个字段进行更新 串行化SERIALIZABLE 确保Transaction01可以多次从一个表中读取到相同的行在Transaction01执行期间禁止其它事务对这个表进行添加、更新、删除操作。可以避免任何并发问题但性能十分低下
各个隔离级别解决并发问题的能力见下表
隔离级别脏读不可重复读幻读READ UNCOMMITTED有有有READ COMMITTED无有有REPEATABLE READ无无有SERIALIZABLE无无无
各种数据库产品对事务隔离级别的支持程度
隔离级别OracleMySQLREAD UNCOMMITTED×√READ COMMITTED√(默认)√REPEATABLE READ×√(默认)SERIALIZABLE√√
Transactional(isolation Isolation.DEFAULT)//使用数据库默认的隔离级别
Transactional(isolation Isolation.READ_UNCOMMITTED)//读未提交
Transactional(isolation Isolation.READ_COMMITTED)//读已提交
Transactional(isolation Isolation.REPEATABLE_READ)//可重复读
Transactional(isolation Isolation.SERIALIZABLE)//串行化
事务属性传播行为
在service类中有a()方法和b()方法a()方法上有事务b()方法上也有事务当a()方法执行过程中调用了b()方法事务是如何传递的合并到一个事务里还是开启一个新的事务这就是事务传播行为
一共有七种传播行为 REQUIRED支持当前事务如果不存在就新建一个(默认)【没有就新建有就加入】 SUPPORTS支持当前事务如果当前没有事务就以非事务方式执行【有就加入没有就不管】 MANDATORY必须运行在一个事务中如果当前没有事务正在发生将抛出一个异常【有就加入没有就抛异常】 REQUIRES_NEW开启一个新的事务如果一个事务已经存在则将这个存在的事务挂起【不管有没有直接开启一个新事务开启的新事务和之前的事务不存在嵌套关系之前事务被挂起】 NOT_SUPPORTED以非事务方式运行如果有事务存在挂起当前事务【不支持事务存在就挂起】 NEVER以非事务方式运行如果有事务存在抛出异常【不支持事务存在就抛异常】 NESTED如果当前正有一个事务在进行中则该方法应当运行在一个嵌套式事务中。被嵌套的事务可以独立于外层事务进行提交或回滚。如果外层事务不存在行为就像REQUIRED一样。【有事务的话就在这个事务里再嵌套一个完全独立的事务嵌套的事务可以独立的提交和回滚。没有事务就和REQUIRED一样】
演示
package com.qcby.tx.service;public interface CheckoutService {void checkout(Integer[] bookIds, Integer userId);
}
package com.qcby.tx.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;Transactional
Service
public class CheckoutServiceImpl implements CheckoutService{Autowiredprivate BookService bookService;//买多本书Overridepublic void checkout(Integer[] bookIds, Integer userId) {for (Integer bookId : bookIds) {bookService.buyBook(bookId,userId);}}
}package com.qcby.tx.controller;import com.qcby.tx.service.BookService;
import com.qcby.tx.service.CheckoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;Controller
public class BookController {Autowiredprivate BookService bookService;Autowiredprivate CheckoutService checkoutService;// public void buyBook(Integer bookId,Integer userId){
// bookService.buyBook(bookId,userId);
// }public void checkout(Integer[] bookIds,Integer userId){checkoutService.checkout(bookIds,userId);}
}在数据库中将用户的余额修改为100元
可以通过Transactional中的propagation属性设置事务传播行为
修改BookServiceImpl中buyBook()上注解Transactional的propagation属性
Transactional(propagation Propagation.REQUIRED)默认情况表示如果当前线程上有已经开启的事务可用那么就在这个事务中运行。经过观察购买图书的方法buyBook()在checkout()中被调用checkout()上有事务注解因此在此事务中执行。所购买的两本图书的价格为80和50而用户的余额为100因此在购买第二本图书时余额不足失败导致整个checkout()回滚即只要有一本书买不了就都买不了
Transactional(propagation Propagation.REQUIRES_NEW)表示不管当前线程上是否有已经开启的事务都要开启新事务。同样的场景每次购买图书都是在buyBook()的事务中执行因此第一本图书购买成功事务结束第二本图书购买失败只在第二次的buyBook()中回滚购买第一本图书不受影响即能买几本就买几本
全注解配置事务
用配置类代替配置文件
package com.qcby.tx.config;import com.alibaba.druid.pool.DruidDataSource;
import org.aspectj.lang.annotation.Before;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;import javax.sql.DataSource;Configuration //配置类
ComponentScan(com.qcby.tx)
EnableTransactionManagement //开启事务管理
public class SpringConfig {Beanpublic DataSource getDataSource(){DruidDataSource dataSource new DruidDataSource();dataSource.setDriverClassName(com.mysql.cj.jdbc.Driver);dataSource.setUsername(root);dataSource.setPassword(123456);dataSource.setUrl(jdbc:mysql://localhost:3306/spring?characterEncodingutf8useSSLfalse);return dataSource;}Bean(name jdbcTemplate)public JdbcTemplate getJdbcTemplate(DataSource dataSource){JdbcTemplate jdbcTemplate new JdbcTemplate();jdbcTemplate.setDataSource(dataSource);return jdbcTemplate;}Beanpublic DataSourceTransactionManager getTransactionManager(DataSource dataSource){DataSourceTransactionManager dataSourceTransactionManager new DataSourceTransactionManager();dataSourceTransactionManager.setDataSource(dataSource);return dataSourceTransactionManager;}}测试
package com.qcby;import com.qcby.tx.config.SpringConfig;
import com.qcby.tx.controller.BookController;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class TestAnno {Testpublic void testTxAllAnnotation(){ApplicationContext applicationContext new AnnotationConfigApplicationContext(SpringConfig.class);BookController accountService applicationContext.getBean(bookController, BookController.class);accountService.buyBook(1, 1);}
}基于xml的声明式事务
参考基于注解的声明式事务
注意基于xml实现的声明式事务必须引入以下依赖
dependencygroupIdorg.springframework/groupIdartifactIdspring-aspects/artifactIdversion6.0.2/version
/dependency 将Spring配置文件中去掉tx:annotation-driven 标签并添加配置
aop:config!-- 配置事务通知和切入点表达式 --aop:advisor advice-reftxAdvice pointcutexecution(* com.qcby.tx.service.*.*(..))/aop:advisor
/aop:config
!-- tx:advice标签配置事务通知 --
!-- id属性给事务通知标签设置唯一标识便于引用 --
!-- transaction-manager属性关联事务管理器 --
tx:advice idtxAdvice transaction-managertransactionManagertx:attributes!-- tx:method标签配置具体的事务方法 --!-- name属性指定方法名可以使用星号代表多个字符 --tx:method nameget* read-onlytrue/tx:method namequery* read-onlytrue/tx:method namefind* read-onlytrue/tx:method namebuy* read-onlytrue/!-- read-only属性设置只读属性 --!-- rollback-for属性设置回滚的异常 --!-- no-rollback-for属性设置不回滚的异常 --!-- isolation属性设置事务的隔离级别 --!-- timeout属性设置事务的超时属性 --!-- propagation属性设置事务的传播行为 --tx:method namesave* read-onlyfalse rollback-forjava.lang.Exception propagationREQUIRES_NEW/tx:method nameupdate* read-onlyfalse rollback-forjava.lang.Exception propagationREQUIRES_NEW/tx:method namedelete* read-onlyfalse rollback-forjava.lang.Exception propagationREQUIRES_NEW//tx:attributes
/tx:advice