简体   繁体   中英

Code assist in (jsp /jstl) view for Spring MVC model objects in Eclipse

In Spring MVC when placing an object in the view model like so:

public String getUser( Model model ) {
    //...fetch user...
    model.addAttribute( "user", user );
    return "viewName";
}

and accessing it's values in the JSP / JSTL view like this:

...
<p>
    ${user.name}
</p>
...

I'm wondering if it is possible to have code assist for the user object in the view?

The IDE I'm using is MyEclipse but it would be interesting to know if this is possible in other editors as well.

Thanks.

Ideally you want the JSP/JSTL standard tags to be agnostic of the technology that supplies these objects but you are correct in that atleast while designing the support will be useful.

However it looks like Intellij IDEA seems to have something similar to what you want http://www.jetbrains.com/idea/features/spring_framework.html (towards the end)!

You have to add a JSP comment like this:

<%--@elvariable id="pet" type="com.mycompany.Pet"--%>

IntelliJ will then autocomplete based on that type.

替代文字
(source: jetbrains.com )

Is using IntelliJ ruled out for you?

In other words: you want code assist for EL (Expression Language, the ${} things)? This is not to be confused with JSP , JSTL nor Spring MVC .

Eclipse doesn't have any builtin EL autocompletion support, the JBoss Tools plugin adds some (JSF) EL autocompletion support. MyEclipse and IntelliJ have code assist for at least implicit EL objects . Not sure about custom EL objects though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM