By using Java 7 and above, we can simply to do this by using the following line.
int i =0;
int n=10;
System.out.println(String.format("%03d", i));
System.out.println(String.format("%03d", n));
int i =0;
int n=10;
System.out.println(String.format("%03d", i));
System.out.println(String.format("%03d", n));
SELECT f.file_id,f.FILETYPE_ID, f.file_obj_l,max_date
FROM FILE_STORE f inner JOIN
(SELECT FILETYPE_ID, max(f1.UPDATETS) as max_date FROM FILE_STORE f1
where FILETYPE_ID in (1, 2, 3)
group by FILETYPE_ID
) a
on a.FILETYPE_ID = f.FILETYPE_ID and a.max_date = f.UPDATETS
<!-- Enable this for eventual integration of file upload functionality-->
<bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver">
<!-- setting maximum upload size -->
<property name="maxUploadSize" value="20000000"/>
</bean>
<html>
<head>
<title>Upload File Request Page</title>
</head>
<body>
<form method="POST" action="uploadFile" enctype="multipart/form-data">
File to upload: <input type="file" name="file"><br /> <br />
Name: <input type="text" name="name"><br /> <br />
<input type="submit" value="Upload"> Press here to upload the file!
</form>
</body>
</html>
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
/**
* Handles requests for the application file upload requests
*/
@Controller
public class FileUploadController {
private static final Logger logger = LoggerFactory
.getLogger(FileUploadController.class);
@RequestMapping(value = "/uploadFile", method = RequestMethod.GET )
public String uploadfile(ModelMap model)
{
return "upload";
}
/**
* Upload file using Spring Controller
*/
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public @ResponseBody
String uploadFileHandler(@RequestParam("name") String name,
@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
// Creating the directory to store file
String rootPath = System.getProperty("catalina.home");
File dir = new File(rootPath + File.separator + "tmpFiles");
if (!dir.exists())
dir.mkdirs();
// Create the file on server
File serverFile = new File(dir.getAbsolutePath()
+ File.separator + name);
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();
logger.info("Server File Location="
+ serverFile.getAbsolutePath());
return "You successfully uploaded file=" + name;
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name
+ " because the file was empty.";
}
}
}
Checkboxes (and radio buttons) are on/off switches that may be toggled by the user. A switch is "on" when the control element's checked attribute is set. When a form is submitted, only "on" checkbox controls can become successful.
<c:forEach items="${classes}" var="class">
<tr>
<td
class="hidden-xs hidden-sm hidden-md hidden-lg ui-state-default">
<input type="hidden" id="classid" name="classid[]"
value='<c:out value="${class.configClassId}"/>'></input> <input
type="hidden" id="displayOrder" name="displayOrder[]"
class="form-control"
value='<c:out value="${class.displayOrder}"/>'></input>
</td>
<td><input type="text" id="internalClassName"
name="internalClassName[]" class="form-control"
placeholder="Class Internal Name"
value='<c:out value="${class.internalClassName}"/>'></td>
<td><input type="text" id="displayName"
name="displayName[]" class="form-control"
placeholder="Display Name"
value='<c:out value="${class.displayName}"/>' /></td>
<td>
<div class="checkbox">
<c:if test="${class.enable!=null && class.enable=='Y'}">
<input type="checkbox" name="enabled[]"
class="form-control chk" value="Y" checked="checked">
</c:if>
<c:if test="${class.enable==null || class.enable!='Y'}">
<input type="checkbox" name="enabled[]"
class="form-control chk" value="Y">
<input type="hidden" name="enabled[]" class="chk" value="N">
</c:if>
</div>
</td>
<td><input type="text" id="searchWeight[]"
name="searchWeight[]" class="form-control"
value='<c:out value="${class.searchWeight}"/>'></td>
<td><input type="hidden" id="fileid" name="fileid[]"
class="form-control"
value='<c:out value="${class.fileStore.fileId}"/>'><img
src="${pageContext.request.contextPath}/download/${class.fileStore.fileId}"></td>
<td>
<div class="input-group">
<span class="input-group-btn"> <span
class="btn btn-default btn-file active">
Browse… <input type="file" id="uploadimage"
name="uploadimage[]" class="form-control" multiple />
</span>
</span> <input type="text" class="form-control" readonly>
</div>
</td>
<td><button type="button" class="removebutton"
title="Remove this class">
<span class="glyphicon glyphicon-remove "></span>
</button></td>
</tr>
</c:forEach>
.on("click", ".chk",function() {
var v = $(this).attr('checked') == 'checked'?'Y':'N';
if (v=='Y')
{
$(this).removeAttr('checked');
$(this).after('<input type="hidden" name="enabled[]" value="N" />');
}
if (v=='N')
{
$(this).attr('checked');
$(this).val( "Y" );
if ($(this).next().attr('class')=='chk')
$(this).next().attr('disabled', true);
}
}
$('#classconfigform')
.formValidation(
{
framework : 'bootstrap',
err : {
container : 'tooltip'
},
row : {
selector : 'td'
},
icon : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
},
fields : {
'internalClassName[]' : {
validators : {
notEmpty : {
message : 'Internal class name is required'
}
}
},
'displayName[]' : {
validators : {
notEmpty : {
message : 'Display name is required'
},
stringLength: {
max: 20,
message: 'The display name must be less than 20 characters long.'
}
}
},
'searchWeight[]' : {
validators : {
notEmpty : {
message : 'Search Weight is required'
},
regexp: {
regexp: '^[19]+$',
message: 'Only 1 and 9 can be chosen. 1 for class always on top.'
}
}
},
'uploadimage[]' : {
validators : {
callback : {
message : 'An image is required',
callback : function(
value,
validator,
$field) {
var $fileid = '';
var $classimg = $field
.closest('tr');
// console.log("classimg:"+$classimg );
$fileid = $classimg
.find(
'#fileid')
.val();
//console.log("fileid:"+$fileid);
//console.log("upload img value:"+value);
if (($fileid == null || $fileid == '')
&& (value == null || value == ''))
return false;
else
return true;
}
},
//end of callback
stringLength: {
max: 30,
message: 'The file name must be less than 30 characters long.'
}
}
}
}
})
@PersistenceContext
private EntityManager emgr;
@Override
@Transactional
public void saveClass(CompanyClass cclass)
throws Exception {
emgr.persist(cclass);
emgr.close();
}
emgr.persist(cclass);
emgr.merge(cclass);