Projection query refers to: click the drop-down box to display the existing data type names in the data dictionary table in the database, and traverse to the drop-down menu without duplication, as shown in the figure
1. Add in the home of ElecSystemDDLAction:
public class ElecSystemDDLAction extends BaseAction<elecsystemddl>{ ElecSystemDDL elecSystemDDL=this.getModel(); //注入数据字典service@Resource(name=IElecSystemDDLService.SERVICE_NAME) IElecSystemDDLService elecSystemDDLService; /** * @Name: home * @Description: 跳转到数据字典页面 * @Parameters: 无 * @Return: String:跳转到system/dictionaryIndex.jsp*/public String home(){// 1:查询数据库中已有的数据类型,返回List<elecsystemddl>集合 List<elecsystemddl> list=elecSystemDDLService.findSystemDDLListByDistinct(); // 2:将ElecSystemDDL对象放入request中 request.setAttribute("list", list);return "home"; } }</elecsystemddl></elecsystemddl></elecsystemddl>
2. Declare the projection query method in IElecSystemDDLService:
public interface IElecSystemDDLService {public static final String SERVICE_NAME="cn.elec.service.impl.ElecSystemDDLServiceImpl"; List<elecsystemddl> findSystemDDLListByDistinct(); }</elecsystemddl>
3. Rewrite in ElecSystemDDLServiceImpl:
public class ElecSystemDDLServiceImpl implements IElecSystemDDLService{//数据字典Dao@Resource(name=IElecSystemDDLDao.SERVICE_NAME)private IElecSystemDDLDao elecSystemDDLDao; /** * @Name: findSystemDDLListByDistinct * @Description: 查询数据库中已有的数据类型,去掉重复值 * @Parameters: 无 * @Return: List:存储数据类型集合*/@Override @Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,readOnly=false)public List<elecsystemddl> findSystemDDLListByDistinct() { List<elecsystemddl> list=elecSystemDDLDao.findSystemDDLListByDistinct();return list; } }</elecsystemddl></elecsystemddl>
4. Declare the projection query method in IElecSystemDDLDao:
public interface IElecSystemDDLDao extends ICommonDao<elecsystemddl> {public static final String SERVICE_NAME="cn.elec.dao.imp.ElecSystemDDLImpl"; List<elecsystemddl> findSystemDDLListByDistinct(); }</elecsystemddl></elecsystemddl>
5. Rewrite this method in ElecSystemDDLImpl:
@Repository(IElecSystemDDLDao.SERVICE_NAME)public class ElecSystemDDLImpl extends ICommonDaoImpl<elecsystemddl> implements IElecSystemDDLDao{/** * @Name: findSystemDDLListByDistinct * @Description: 查询数据库中已有的数据类型,去掉重复值 * @Parameters: 无 * @Return: List:存储数据类型集合*/@Overridepublic List<elecsystemddl> findSystemDDLListByDistinct() {//返回List集合List<elecsystemddl> systemList = new ArrayList<elecsystemddl>();/**方法一:投影查询一个字段返回List<object>中 String hql="SELECT DISTINCT o.keyword FROM ElecSystemDDL o"; List<object> list = this.getHibernateTemplate().find(hql); //组织页面返回结果 if(list!=null&&list.size()>0){ for(Object obj:list){ ElecSystemDDL elecSystemDDL = new ElecSystemDDL(); //设置数据类型,并添加到systemList elecSystemDDL.setKeyword(obj.toString()); systemList.add(elecSystemDDL); } }*///方法二:使用hql语句直接将投影查询的字段放置到对象中String hql="SELECT DISTINCT new cn.elec.domain.ElecSystemDDL(o.keyword) FROM ElecSystemDDL o"; systemList=this.getHibernateTemplate().find(hql);return systemList; } }</object></object></elecsystemddl></elecsystemddl></elecsystemddl></elecsystemddl>
The second query plan requires creating a constructor with parameters in ElecSystemDDL:
public ElecSystemDDL() {//无参构造方法} public ElecSystemDDL(String keyword) {//带参构造方法this.keyword=keyword; }
6. Traverse in dictionaryIndex.jsp:
Because the List
<tr> <td>类型列表:</td> <td> <!-- 方案一 <select name="keyword" class="bg" style="width:180px" onchange="changetype()"> <option value="jerrynew"></option> <s:iterator value="#request.list" var="sys"> <option value="<s:property value="#sys.keyword"/>"> <s:property value="#sys.keyword"/> </option> </s:iterator> </select> --> <!-- 方案二 --> <select> </select> </td> </tr>
Test, On the data dictionary homepage function page, the drop-down menu can correctly display the type name.
1. Projection query of hql and sql statements:
(1) If the projection query is a field, List
String hql = "SELECT DISTINCT o.keyword FROM ElecSystemDDL o"; List<object> list = this.getHibernateTemplate().find(hql);</object>
(2) If the projection query is for multiple fields, List
String hql = "SELECT DISTINCT o.keyword,o.ddlName FROM ElecSystemDDL o"; List<object> list = this.getHibernateTemplate().find(hql);</object>
(3) If the projection query is for multiple fields, List
String hql = "SELECT o,o.ddlName FROM ElecSystemDDL o"; List<object> list = this.getHibernateTemplate().find(hql);</object>
The first value of the array is an ElecSystemDDL object, and the second value of the array represents the value of the field ddlName.
(4) If the projection query is an object, List
String hql = "SELECT o FROM ElecSystemDDL o"; List<elecsystemddl> list = this.getHibernateTemplate().find(hql);</elecsystemddl>
(5) If it is an hql statement, use the hql statement to directly place the fields of the projection query into the object, such as
String hql = "SELECT DISTINCT new cn.itcast.elec.domain.ElecSystemDDL(o.keyword) FROM ElecSystemDDL o"; List<elecsystemddl> list = this.getHibernateTemplate().find(hql);</elecsystemddl>
2. The page uses select to traverse List
(1) Solution 1: Use
<select> <option></option> <iterator> <option></option>"> <property></property> </iterator> </select>
(2) Solution Two: Use
<select> </select>
The above is the detailed content of Projection query method of data dictionary design. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.