Springboot+JdbcTemplate +thymeleaf 页面 做迷你版的bug系统
https://www.cnblogs.com/qianjinyan/p/10065160.html?
在我上一篇隨筆中介紹了關(guān)于要做的系統(tǒng)的數(shù)據(jù)結(jié)構(gòu),連接如上
?
今天實(shí)現(xiàn)連接mssql server,查詢出所有buglist的效果,CRUD
?
實(shí)現(xiàn)方法極其簡(jiǎn)單,如下圖
?
?
Bug類對(duì)象中列出字段
?
package com.jasmine.demo.bean;public class Bug {private long id;private String pname;private String crname;private String crnum;private String tasknum;private String oname;private String description;private String rca;private String solution;private String developer;private String tester;private String creationdt;private String updatedt;public long getId() {return id;}public void setId(long id) {this.id = id;}public String getPname() {return pname;}public void setPname(String pname) {this.pname = pname;}public String getCrname() {return crname;}public void setCrname(String crname) {this.crname = crname;}public String getCrnum() {return crnum;}public void setCrnum(String crnum) {this.crnum = crnum;}public String getTasknum() {return tasknum;}public void setTasknum(String tasknum) {this.tasknum = tasknum;}public String getOname() {return oname;}public void setOname(String oname) {this.oname = oname;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}public String getRca() {return rca;}public void setRca(String rca) {this.rca = rca;}public String getSolution() {return solution;}public void setSolution(String solution) {this.solution = solution;}public String getDeveloper() {return developer;}public void setDeveloper(String developer) {this.developer = developer;}public String getTester() {return tester;}public void setTester(String tester) {this.tester = tester;}public String getCreationdt() {return creationdt;}public void setCreationdt(String creationdt) {this.creationdt = creationdt;}public String getUpdatedt() {return updatedt;}public void setUpdatedt(String updatedt) {this.updatedt = updatedt;}@Overridepublic String toString() {return "Bug{" +"id=" + id +", pname='" + pname + '\'' +", crname='" + crname + '\'' +", crnum='" + crnum + '\'' +", tasknum='" + tasknum + '\'' +", oname='" + oname + '\'' +", description='" + description + '\'' +", rca='" + rca + '\'' +", solution='" + solution + '\'' +", developer='" + developer + '\'' +", tester='" + tester + '\'' +", creationdt='" + creationdt + '\'' +", updatedt='" + updatedt + '\'' +'}';}public Bug() {super();}public Bug(long id, String pname, String crname, String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester, String creationdt, String updatedt) {this.id = id;this.pname = pname;this.crname = crname;this.crnum = crnum;this.tasknum = tasknum;this.oname = oname;this.description = description;this.rca = rca;this.solution = solution;this.developer = developer;this.tester = tester;this.creationdt = creationdt;this.updatedt = updatedt;} }?
BugService 接口中定義了增刪查改等方法
具體實(shí)現(xiàn)是在對(duì)應(yīng)的impl中 package com.jasmine.demo.service;import com.jasmine.demo.bean.Bug;import java.util.List;public interface BugService {List<Bug> findAll();Bug findById(int id);int create(String pname,String crname,String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester);int update(long id, String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester);int deleteByID(int id);}
package com.jasmine.demo.service.impl;import com.jasmine.demo.bean.Bug; import com.jasmine.demo.jdbc.BugRowMapper; import com.jasmine.demo.service.BugService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service;import java.util.List;@Service public class BugServiceImpl implements BugService {@Autowiredprivate JdbcTemplate jdbcTemplate;@Overridepublic List<Bug> findAll() {String sql = "SELECT BUG_ID,PROJECT_NAME,CR_NAME,BUG_CR_NUM,BUG_TASK_NUM,OBJECT_NAME,BUG_DESCRIPTION\n" +",BUG_RCA,BUG_SOLUTION,B.EMPLOY_NAME DEVELOPER,A.EMPLOY_NAME TESTER,QA_CREATIONDT,QA_UPDATEDT,BUG_DELETED_FLAG\n" +"FROM QA_BUGLIST\n" +"JOIN QA_PROJECT ON BUG_PROJECT_ID = PROJECT_ID\n" +"JOIN QA_CRTYPE ON CR_ID = BUG_CR_TYPE_ID\n" +"JOIN QA_RTYPE ON OBJECT_ID = QA_TYPE_ID\n" +"JOIN QA_EMPLOY A ON A.[EMPLOY_ID] = QA_TESTER_ID AND A.[EMPLOY_GROUP] = 1 ---表示測(cè)試\n" +"JOIN QA_EMPLOY B ON B.[EMPLOY_ID] = QA_ASSIGNEE_ID AND B.[EMPLOY_GROUP] = 2 ---表示開發(fā)人員\n" +"WHERE BUG_DELETED_FLAG =0 order by 1 desc";List<Bug> bugs = jdbcTemplate.query(sql,new BugRowMapper() );return bugs;}@Overridepublic Bug findById(int id) {String sql = "SELECT BUG_ID,PROJECT_NAME,CR_NAME,isnull(BUG_CR_NUM,'') as BUG_CR_NUM,isnull(BUG_TASK_NUM,'') as BUG_TASK_NUM,OBJECT_NAME,isnull(BUG_DESCRIPTION,'') as BUG_DESCRIPTION\n" +",isnull(BUG_RCA,'') as BUG_RCA,isnull(BUG_SOLUTION,'') as BUG_SOLUTION,B.EMPLOY_NAME DEVELOPER,A.EMPLOY_NAME TESTER,QA_CREATIONDT,QA_UPDATEDT,BUG_DELETED_FLAG\n" +"FROM QA_BUGLIST\n" +"JOIN QA_PROJECT ON BUG_PROJECT_ID = PROJECT_ID\n" +"JOIN QA_CRTYPE ON CR_ID = BUG_CR_TYPE_ID\n" +"JOIN QA_RTYPE ON OBJECT_ID = QA_TYPE_ID\n" +"JOIN QA_EMPLOY A ON A.[EMPLOY_ID] = QA_TESTER_ID AND A.[EMPLOY_GROUP] = 1 ---表示測(cè)試\n" +"JOIN QA_EMPLOY B ON B.[EMPLOY_ID] = QA_ASSIGNEE_ID AND B.[EMPLOY_GROUP] = 2 ---表示開發(fā)人員\n" +"WHERE BUG_DELETED_FLAG =0 and BUG_ID = ?";Bug bug = jdbcTemplate.queryForObject(sql,new BugRowMapper(),id);return bug;}@Overridepublic int create(String pname,String crname,String crnum, String tasknum, String oname, String description, String rca, String solution, String developer, String tester) {String sql ="INSERT QA_BUGLIST(BUG_PROJECT_ID,BUG_CR_TYPE_ID,BUG_CR_NUM,BUG_TASK_NUM,QA_TYPE_ID,BUG_DESCRIPTION,BUG_RCA,BUG_SOLUTION,QA_ASSIGNEE_ID,QA_TESTER_ID,QA_CREATIONDT,QA_UPDATEDT)\n" +"VALUES(?,?,?,?,?,?,?,?,?,?,GETDATE(),GETDATE())";return jdbcTemplate.update(sql,pname,crname,crnum,tasknum,oname,description,rca,solution,developer,tester);}@Overridepublic int update(long id, String crnum, String tasknum, String description, String rca, String solution, String developer, String tester,String oname){String sql = "update QA_BUGLIST set BUG_CR_NUM =?,BUG_TASK_NUM =?,BUG_DESCRIPTION=?,BUG_RCA=?,BUG_SOLUTION= ?,QA_UPDATEDT =getdate() where BUG_ID = ?";System.out.println(sql);return jdbcTemplate.update(sql,crnum,tasknum,description,rca,solution,id);}@Overridepublic int deleteByID(int id) {String sql = "update QA_BUGLIST set BUG_DELETED_FLAG = 1, BUG_DELETED_COMMENT = '邏輯刪除' where BUG_ID = ?";System.out.println(sql);int count = jdbcTemplate.update(sql,id);return count;} }
DB的配置寫在application.xml中
啟動(dòng)類之后,跳轉(zhuǎn)的所有頁(yè)面,寫在controller中,
?
?
啟動(dòng)后,打開連接,看到自己的數(shù)據(jù)?
接下來要做的就是讓頁(yè)面好看一點(diǎn),這樣的數(shù)據(jù)看不清楚
JdbcTemplate
thymeleaf
?
頁(yè)面跳轉(zhuǎn)等等,頁(yè)面比較丑,還沒做分頁(yè),搜尋條件也沒有添加
1. 查看所有bug
2. 查看指定bug的詳細(xì)信息
點(diǎn)擊查看按鈕后顯示單個(gè)bug的信息
3. 刪除單列bug信息,點(diǎn)擊單個(gè)bug信息后面的刪除按鈕即可刪除,刪除之前最好有確定按鈕用來提示,以免誤刪
4. 更新,我這邊做在查看單個(gè)詳細(xì)列表頁(yè)面中,如上圖,有信息更新按鈕,點(diǎn)擊后帶入原先的參數(shù)跳轉(zhuǎn)到更新頁(yè)面,在新的頁(yè)面進(jìn)行更新,然后保存
?
5. 新增bug頁(yè)面,在查看所有bug頁(yè)面有新增按鈕,點(diǎn)擊進(jìn)入如下頁(yè)面,保存進(jìn)行新增操作
?
?源代碼提交在github地址如下:
https://github.com/JasmineQian/TestPlatform
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/qianjinyan/p/10097451.html
總結(jié)
以上是生活随笔為你收集整理的Springboot+JdbcTemplate +thymeleaf 页面 做迷你版的bug系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 12JDBC
- 下一篇: 数组常见的遍历循环方法、数组的循环遍历的