上QQ阅读APP看书,第一时间看更新
The Alter function
The following code shows how the Alter function renders the Home template by invoking the ExecuteTemplate method with the writer and customers arrays as parameters:
// Alter - execute template
func Alter(writer http.ResponseWriter, request *http.Request) {
var customer Customer
var customerId int
var customerIdStr string
customerIdStr = request.FormValue("id")
fmt.Sscanf(customerIdStr, "%d", &customerId)
customer.CustomerId = customerId
customer.CustomerName = request.FormValue("customername")
customer.SSN = request.FormValue("ssn")
UpdateCustomer(customer)
var customers []Customer
customers = GetCustomers()
template_html.ExecuteTemplate(writer,"Home",customers)
}