1、修改—回显
后台代码
CompanyController.java
- src\main\java\com\smp\web\controller\company
//修改
@RequestMapping(path="/toEdit",method = RequestMethod.GET)
public String toEdit(){
return "company/company-update";
}
TestCompanyService.java测试
- src\test\java\com\smp\service\company
//修改
@Test
public void test04(){
//通过id查找显示,并修改
String id = "b545a29f-7d1e-4e92-b40e-b96c75dac71d";
Company company = service.findById(id);
l.info(company+" ");
}
ICompanyService.java
- src\main\java\com\smp\service\company
//根据id进行修改
Company findById(String id);
CompanyServiceImpl.java
- src\main\java\com\smp\service\company\impl
//根据id进行查询--->修改回显
@Override
public Company findById(String id) {
Company company=ICompanyDao.findById(id);
return company;
}
ICompanyDao.java
- src\main\java\com\smp\dao\company
//修改查找回显
Company findById(String id);
ICompanyDao.xml
- src\main\resources\com\smp\dao\company
<!--//修改查找回显
Company findById(String id);-->
<select id="findById" parameterType="String" resultType="company">
select
id,
name ,
expiration_date as expirationDate ,
address,
license_id as licenseId ,
representative ,
phone ,
company_size as companySize ,
industry ,
remarks ,
state,
balance ,
city
from ss_company
where id=#{id}
</select>
前台代码
CompanyController.java
- src\main\java\com\smp\web\controller\company
//修改-->回显
@RequestMapping(path="/toEdit",method = RequestMethod.GET)
public String toEdit(String id,Model model){
l.info("toEdit id="+id);
Company company=iCompanyService.findById(id);
l.info("toEdit company="+company);
model.addAttribute(company);
return "company/company-update";
}
company-list.jsp
- src\main\webapp\WEB-INF\pages\company
<button type="button" class="btn bg-olive btn-xs" onclick='location.href="${path}/company/toEdit.do?id=${item.id}"'>编辑</button>
- 修改界面
2、修改—保存
有了修改,需要把修改的值传回数据库,并显示
后台代码
TestCompanyService.java测试
- src\test\java\com\smp\service\company
//修改--传值
@Test
public void test05(){
String id="7f2044e6-96d2-46e9-ae7a-dcfbd81b1ab8";
Company company = service.findById(id);
l.info(company+" ");
//模拟修改
company.setCity("北京");
l.info(company+"");
service.updateCompany(company);
}
ICompanyService.java
- src\main\java\com\smp\service\company
//修改
void updateCompany(Company company);
CompanyServiceImpl.java
- src\main\java\com\smp\service\company\impl
//修改传值
@Override
public void updateCompany(Company company) {
//调用操作数据库
iCompanyDao.update(company);
}
ICompanyDao.java
- src\main\java\com\smp\dao\company
//修改传值
void update(Company company);
ICompanyDao.xml
- src\main\resources\com\smp\dao\company
<!--//修改传值
void update(Company company);-->
<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>
前台代码
CompanyController.java
- src\main\java\com\smp\web\controller\company
//修改传值
@RequestMapping(path = "/update",method = RequestMethod.POST)
public String update(Company company){
l.info("update company="+company);
iCompanyService.updateCompany(company);
//跳转到列表页面
return "redirect:/company/toList.do";
}
company-list.jsp
- src\main\webapp\WEB-INF\pages\company
<button type="button" class="btn bg-olive btn-xs" onclick='location.href="${path}/company/toEdit.do?id=${item.id}"'>编辑</button>
company-update.jsp
- src\main\webapp\WEB-INF\pages\company