打开添加页面

Day32项目saas-export项目-添加_jsp

CompanyController

//添加 1 打开添加页面
@RequestMapping(path="/toAdd",method = RequestMethod.GET)
public String toAdd(){
return "company/company-add";
}

后台代码

TestCompanyService

@Test
public void test02(){
//1:将表单数据通过Service正确写入到数据库
// public Company(String id, String name, Date expirationDate, String address, String licenseId, String representative, String phone, String companySize, String industry, String remarks, Integer state, Double balance, String city)
Company company = new Company("id1","name1",new Date(),"address1","licenseId","representative","phone","companySize","industry","remarks",0,100.0,"city");
//保存
service.saveCompany(company);
}

ICompanyService

void saveCompany(Company company);

CompanyServiceImpl

@Override
public void saveCompany(Company company) {
//当前数据库的id不是自增长的。
//02e1da04-43f8-42e1-a4c2-66e162c6f4a5 uuid 全球唯一
String id = UUID.randomUUID().toString();
company.setId(id);
iCompanyDao.save(company);
}

​当前数据库的id不是自增长的。uuid 全球唯一​

ICompanyDao

void save(Company company);

ICompanyDao.xml

<insert id="save" parameterType="company">
insert into ss_company
(
id ,
name ,
expiration_date ,
address ,
license_id ,
representative ,
phone ,
company_size ,
industry ,
remarks ,
state ,
balance ,
city

)
values
(

#{id },
#{name },
#{expirationDate },
#{address },
#{licenseId },
#{representative },
#{phone },
#{companySize },
#{industry },
#{remarks },
#{state },
#{balance },
#{city}


)

</insert>

运行,先从domain->dao->service->web 先clean再install,否则会出现​​符号找不到​

前台代码

company-add.jsp

》springmvc要求表单 提交的数据的参数名,要跟实现类中的变量名一致。

Day32项目saas-export项目-添加_表单_02

CompanyController

//${path}/company/add.do  技巧1:表单的name值对应实体类的变量名
@RequestMapping(path="/add",method = RequestMethod.POST)
public String add(Company company){
l.info("add company="+company);
iCompanyService.saveCompany(company);
return "redirect:/company/...";//跳转到列表页面
}