1 分析
更新,就是将回显的数据,经过修改之后,并同步数据数据库中!
2 后台代码
TestCompanyService
@Test
public void test05(){
//
String id = "2a126a35-3178-46c5-9b48-ea3fa187386b";
Company company = service.findById(id);
l.info(company+" ");
//模拟修改
company.setCity("北京");
l.info(company+" ");
//将修改后的数据保存到数据库
service.updateCompany(company);
}
ICompanyService
void updateCompany(Company company);
CompanyServiceImpl
@Override
public void updateCompany(Company company) {
//调用dao操作数据库
iCompanyDao.update(company);
}
ICompanyDao
void update(Company company);
ICompanyDao.xml
<update id="update" parameterType="company">
update ss_company
set name = #{name },
expiration_date= #{expirationDate},
address = #{address },
license_id = #{licenseId },
representative = #{representative },
phone = #{phone },
company_size = #{companySize },
industry = #{industry },
remarks = #{remarks },
state = #{state },
balance = #{balance },
city = #{city }
where id = #{id}
</update>
3 前台代码
company-update.jsp
action="${path}/company/update.do"
CompanyController
//${path}/company/update.do
@RequestMapping(path="/update",method = RequestMethod.POST)
public String update(Company company){ //表单的参数名要与实体类的变量名一样。
l.info("update company="+company);
iCompanyService.updateCompany(company);
return "redirect:/company/toList.do";//跳转到列表页面
}