I have a program that uses annotations and another one that is using fist one as dependency. I was able to do that thanks to persistance.xml. But I added validator class to first one (desktop app) because second one is web app and have some new possibilities like attaching files so I created validator class for it. At this moment I created dao and model layer for it in second program sources but I want to add it to first one instead.
If I don't add tag #Entity to this class then I can;t add it to persistence.xml so my second program can't find that source.
Is it okay to add #Entity when Validator does not and will not use database and there is no table for it?
I know it works because I tested it, but I wonder if this is good attitude.
If not, how can I make it done different way?
Also if validator class is empty, I mean it doesn't have any fields, only one method to validate that return true or false, is it ok to make dao layer and model layer for it?
Atm it is: Validator class, ValidatorDao class and ValidatorDaoInterface interface.
Is that correct approach?
model:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package xxx.model;
/**
*
* #author
*/
public class Validator {
}
dao:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package xxx.dao;
import javax.servlet.http.Part;
/**
*
* #author
*/
public class ValidatorDao implements ValidatorDaoInterface {
#Override
public boolean validateFile(Part part, int numberOfFiles) {
/*TODO*/
}
}
interface:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package xxx.dao;
import javax.servlet.http.Part;
/**
*
* #author
*/
public interface ValidatorDaoInterface {
public boolean validateFile(Part part, int numberOfFiles);
}
yes you can exclude classes that are not annotated with #Entity in your Persitence.xml file.
Just add this line to your persitence-unit
<exclude-unlisted-classes>true</exclude-unlisted-classes>
and you won't have to annotate your validator classes with #Entity because that's wrong.
Related
I would love to know a best practice of adding a secondary author who added or modified a java class who is other than the first author. This seems to be a better practice that provides clarity other than commits in git. Please refer to below as a reference. What I have included is the first author of the code.
import lombok.extern.log4j.Log4j2;
import redis.clients.jedis.exceptions.JedisConnectionException;
/**
* #author Lahiru_Wijesekara
*/
#ControllerAdvice
#Log4j2
public class ExceptionHandlerController {
You can add second author with new #author.
In your example:
import lombok.extern.log4j.Log4j2;
import redis.clients.jedis.exceptions.JedisConnectionException;
/**
* #author Lahiru_Wijesekara
* #author Firstname Surname
*/
#ControllerAdvice
#Log4j2
public class ExceptionHandlerController {
For example, InteliiJ understands this syntax and lists the authors with a decimal point. It's example from Spring #RestController annotation in my IDE:
As you can see in documentation authors are also given in this format.
I need to link to a package in JavaDoc.
Example:
#param example description (see {#link com.example.packagename this})
With the code above, I get this message:
warning - Tag #link: reference not found: com.example.packagename
Linking to a class in the same package works fine, but I need to link directly to the package.
It's not possible with #link.
Create package.html file or a single package-info.java in your com.example.packagename
/**
* This is packagename
*/
package com.example.packagename;
Then you can link to this package by using #see.
/**
* #param example description
* #see com.example.packagename
*/
void doWork(String example) {
}
Now you android studio will show the documentation as follow:
By clicking on com.example.packagename, the javadoc inside package-info.java will be shown.
Note:
Instead of linking packagename directly, You can use <a> tag:
* #see Packagename
I just want when i creat new package and i check the Create package.info.java check box look like this
#ParametersAreNonnullByDefault
package net.pkg.main.foo;
import javax.annotation.ParametersAreNonnullByDefault;
but right now it just look like this
/**
* #author myname
*
*/
package net.pkg.main.foo;
My question: is there any way to edit default package-info template in eclipse?
Thanks in advance <3 <3.
I've just started using the javadoc tool to create documentation for a package containing a servlet class. It's working as expected for every class except the servlet, where the description doesn't appear.
After trial and error I narrowed down the cause to the #WebServlet annotation I use to declare the servlet for Tomcat. I'd rather not remove this annotation if it can be avoided. Is there an easy workaround that I could use?
This is the relevant section of my code:
import javax.servlet.annotation.WebServlet;
#WebServlet("/MyServlet")
/**
* MyServlet description
*
* #author ViscountRandom
* #since 2014-08-26
*/
public class MyServlet extends HttpServlet {
...
The resulting javadoc page can be seen here (note the description is missing and the #WebServlet annotation appears above the class name).
Thanks in advance for any help you can offer.
EDIT: I have tried repositioning the annotation in my code but that had no effect.
For me, it seems to be working, see
/**
* My javadoc
* <br>25/08/2014
*/
#WebServlet
public class MyServlet {
}
generates
while
#WebServlet
/**
* My javadoc
* <br>25/08/2014
*/
public class MyServlet {
}
generates
I am using Java 7.
If you just want your javadoc to go right above the method declaration in the source code, you can still try
/**
* My javadoc
* <br>25/08/2014
*/
#WebServlet public class MyServlet {
}
which will generate
I would like to have the cursor in the JavaDoc area when creating interfaces, classes, etc. in NetBeans. You can use ${cursor} for non-file-based templates, but this doesn't work for file templates.
<#if package?? && package != "">
package ${package};
</#if>
/**
* ${cursor} <-- Inserts a message that "cursor" is an unknown variable. :(
*
* #author ${user}
*/
public class ${name}
{
}
Is there a similar mechanism for file templates?
For some reason this feature hasn't been implemented (yet). See this issue for details.