A. The deployment of UI resources
1. Copy the project page to my project directory
2. Open Code FIG index.jsp found:
If you find access index.jsp will jump to login.do, so the need to write code in LoginController, so that the page to jump to the main page (main.jsp)
Code below (comment @Controller not forget to put on a class):
@Controller public class LoginController { / ** * execution flow * 1. Visit the home page * HTTP: localhost: 8080 / index.jsp * 2. index.jsp * location.href = "login.do" * 3. forwarded to the main. JSP * / @ RequestMapping ( "/ the Login" ) public String the Login () { // the current default login is successful jump to the home page main.jsp return "Home / main" ; } }
The page will jump to main.jsp
code show as below:
LoginController code is as follows:
Test results:
For the iframe tag:
II. Adding enterprise
Click the New button will jump to company-add.jsp (data code shown See yesterday code)
Enter company-add.jsp will find that this form of action is:
It is necessary to process this request in CompanyController:
/ ** * Add a page to enter the * function entry: Click New Enterprise list * Request Address: HTTP: localhost: 8080 / Company / toAdd.do * Response Address: /WEB-INF/pages/company/company-add.jsp * * @return * / @RequestMapping ( "TOADD" ) public String TOADD () { return "Company / the Add-Company" ; }
Test Results:
Jump to successfully add pages
View company-add.jsp last page submission form found at:
In the processing request CompanyController:
/ ** * add enterprise / modify business * * @param Company * @return * / @ RequestMapping ( "Edit" ) public String Edit (Company Company) { // according to id to determine whether to add or modify IF (StringUtils.isEmpty (Company .getId ())) { // If the id is null companyService.save (Company); } the else { // if id is not null companyService.update (Company); } // successfully added to the list interface redirected return "the redirect : /company/list.do " ; }
In this code handled two requests, is to add a business, another is to modify the enterprise (the Save button after clicking the Edit button)
Depending on whether the request id to determine whether there is a request which, added business is no id, but the company is modifying the id. Finally, the preparation method, and configure the mapper mapping file in the service and dao
CompanyService Code:
/ ** * save user * @param Company * / void Save (Company Company); / ** * Modify User * @param Company * / void Update (Company Company);
CompanyServiceImpl Code:
/ ** * save user * @param Company * / @Override public void Save (Company Company) { // set the primary key company.setId (UUID.randomUUID () toString ().); CompanyDao.save (Company); } / ** * modify user * @param Company * / @Override public void Update (Company Company) { companyDao.update (Company); }
Wherein the save () method to set the primary key stored in the database, because if the primary key is not provided, the first may be added, but not the second, as a primary key will be repeated
so disposed directly in the save () primary key
UUID.randomUUID () can be a 32-bit globally unique random code
dao interface code:
/ ** * save user * @param Company * / void Save (Company Company); / ** * Modify User * @param Company * / void Update (Company Company);
dao.xml configuration file code:
<!--保存企业--> <insert id="save"> insert into ss_company ( expiration_date, id, name, address, license_id, representative, phone, company_size, industry, remarks, state, balance, city ) VALUES ( #{expirationDate}, #{id}, #{name}, #{address}, #{licenseId}, #{representative}, #{phone}, #{companySize}, #{industry}, #{remarks}, #{state}, #{balance}, #{city} ) </insert> <!--更新企业--> <update id="update"> update ss_company set expiration_date=#{expirationDate}, name=#{name}, 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>
Test results page:
Modify business
View company-list.jsp page found:
In the processing request CompanyController:
/ ** * enter the edit page * function entrance: company-list.jsp list click Edit * Request Address: HTTP: // localhost : 8080 / Company / toUpdate.do * Request parameters: id modification companies the above mentioned id * Response Address: / INF-the WEB / Pages and the / company / company-update.jsp * / @ RequestMapping ( "toUpdate" ) public String toUpdate (String id, Model Model) { // according to corporate id inquiry company company = companyService.findById (id); / / save model.addAttribute ( "Company" , Company); // forward return "Company / Company-Update" ; }
service codes:
/ ** * Based on company business query id * @param id * @return * / Company findById (String id);
CompanyServiceImpl Code:
/ ** * Based on company business query id * @param id * @return * / @Override public Company findById (String id) { return companyDao.findById (id); }
dao Code:
/ ** * Based on company business query id * @param id * @return * / Company findById (String id);
mapper mapping file code:
<! - according to business enterprise query id -> < the SELECT id = "findById" resultMap = "BaseResultMap" > the SELECT * the FROM ss_company the WHERE id = # {id} </ the SELECT >
Test results page:
Save changes in the above operation has been done!
Delete business
View company-list.jsp page code found:
In the processing request CompanyController:
/ ** * Remove enterprises * function entrance: Company-list.jsp * Request Address: HTTP: // localhost :? 8080 / Company / delete.do the above mentioned id = ............ * / @ @RequestMapping ( "the delete" ) public String the delete (String the above mentioned id) { // delete the enterprises according to the above mentioned id companyService.delete (the above mentioned id); return "redirect: /company/list.do" ; }
service codes:
/ ** * Remove enterprises according to the above mentioned id * @param the above mentioned id * / void the Delete (String the above mentioned id);
CompanyServiceImpl Code:
/ ** * Remove enterprises according to the above mentioned id * @param the above mentioned id * / @Override public void the Delete (String the above mentioned id) { companyDao.delete (the above mentioned id); }
dao level code:
/ ** * Remove enterprises according to the above mentioned id * @param the above mentioned id * / void the Delete (String the above mentioned id);
mapper mapping file code:
<-! Deleted enterprises according to the above mentioned id -> < the Delete the above mentioned id = "the Delete" > DELETE the FROM ss_company the WHERE the above mentioned id = # {the above mentioned id} </ the Delete >