阅读以下代码:
public class selectTable {
public static ResultSet rSet;
public static int total=0;
public static ResultSet onLoad_Opetations(Connection Conn, int rownum,String sql)
{
int rowNum=rownum;
int totalrec=0;
try
{
Conn=ConnectionODBC.getConnection();
Statement stmt = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sqlStmt = sql;
rSet = stmt.executeQuery(sqlStmt);
total = rSet.getRow();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("Total Number of Records="+totalrec);
return rSet;
}
}
Run Code Online (Sandbox Code Playgroud)
下面的代码不显示实际总数:
total = rSet.getRow();
Run Code Online (Sandbox Code Playgroud)
我的jTable显示4记录在jTable但总计= 0; 当我通过调试评估时,它显示:
total=(int)0;
Run Code Online (Sandbox Code Playgroud)
而不是总数=(int)4如果我使用
rSet=last(); above from the code total = rSet.getRow();
Run Code Online (Sandbox Code Playgroud)
总计显示准确值= 4但rSet什么都不返回.然后jTable是空的.告诉我!
我在堆栈溢出文章中看到很多评论我发现@Transactional与@Service或@Controller一起使用的某些事情
"通常,应该在服务层进行交易."
"正常情况是在服务层级注释"
"认为事务属于服务层.它是了解工作单元和用例的人.如果你有几个DAO注入到需要在单个事务中协同工作的服务,那么这是正确的答案." [资源]
使用带有@service层的@transactional的缺点
如果我有2个方法,例如saveUser()和saveEmail()(因为我将电子邮件存储在数据库中以便稍后发送 - 就像一个队列)我会在我的服务中创建一个方法saveUserAndSendEmail(用户用户),它将是事务性的.[资源]
这意味着我在服务层创建了许多方法,而不是一个Save Generic Method,如下所示
public <T> long save(T entity) throws DataAccessException {
Session session = sessionFactory.getCurrentSession();
long getGenVal=(Long) session.save(entity);
return getGenVal;
}
Run Code Online (Sandbox Code Playgroud)
根据上面的解决方案,这意味着我们有很多方法,如以下LOL ..
public <T> long saveAccount(T entity)....
public <T> long saveWithAuditLog(T entity, K entity1)....
public <T> long saveWithAuditLogAndEntries(T entity, K entity, M entity)....
克服这种情况
我在@Controller中使用@Transactional,只需制作一个通用保存方法,并使用这个简单的保存方法保存所有实体/模型.如果任何方法无法保存,则控制器中的所有事务都会成功回滚.
确保@Transactional应与@Controller一起使用的其他情况
在@Controller中:
pt.save(entity1);
pt.save(entity2);
int a = 2/0;
pt.save(entity3);
Run Code Online (Sandbox Code Playgroud)
如果@Transactional on Service,前2个实体成功保存,但第三个不回滚所有事务
如果@Tratroller上的@Transactional,所有事务回滚都会发生异常
为什么堆栈溢出问道,"不要在控制器中进行事务处理.将它们放在服务层类中."? [资源]
我在eclipse中使用JSF Project制作文件faces-config.xml会出错
Referenced file contains errors (jar:file:/D:/eclips/eclipse k/plugins/org.jboss.tools.jst.web_3.5.0.Final-v20130717-0309-B75.jar!/catalog/web-facesconfig_2_2.xsd).
Run Code Online (Sandbox Code Playgroud)
faces-config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
Run Code Online (Sandbox Code Playgroud)
当我删除以下行时,faces-config.xml中的错误指示消失
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd
Run Code Online (Sandbox Code Playgroud)
更新我如何解决此问题?
我有下表:
CREATE TABLE `Foo` (
`id` int NOT NULL,
`FirstName` varchar(255) NULL,
`LastName` varchar(255) NOT NULL DEFAULT 'NONE',
PRIMARY KEY (`id`)
);
Run Code Online (Sandbox Code Playgroud)
当我运行以下查询时,它采用默认值'NONE':
INSERT INTO Foo (`FirstName`) VALUES('FOO');
Run Code Online (Sandbox Code Playgroud)
当我运行以下查询时:
INSERT INTO Foo (`FirstName`, `LastName`) VALUES('FOO', NULL);
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:
[Err] 1048 - Column 'LastName' cannot be null
我想要实现的是,如果一个值是NULL那么 MySQL 应该使用DEFAULT值。
有人知道解决方案吗?
我有以下格式的数据:
(虚拟条目)(id = posGridView)

当我处理销售时,一张小收据会自动打印所选列,而不是所有列.
由于此网格视图中的所有数据都可用,如何使用jquery以任何格式动态打印它?
编辑
实际上我想从上面的网格视图中动态打印这种格式

我收到一个包含xml或json内容的String.
如果String包含json内容,我使用jackson(java api)将JSON转换为Java对象
如果它包含xml内容,我使用JAXB将XML内容转换为Java对象(Unmarshalling).
如何检查是否在该字符串中收到xml或json?
富1
public class Foo1{
private Long id;
private String code;
private String name;
private Boolean rState;
private String comments; // Contain json data
private String attachments; // Contain json data
}
Run Code Online (Sandbox Code Playgroud)
富2
public class Foo2{
private Long id;
private String code;
private String name;
private Boolean rState;
private List comments;
private List attachments;
}
Run Code Online (Sandbox Code Playgroud)
转换值
new ObjectMapper().convertValue(foo1, Foo2.class);
Run Code Online (Sandbox Code Playgroud)
当我调用转换值时,json字符串是否可以自动转换为列表?
我想在mysql(而不是时间戳)中将日期设置为日期的默认值,但会出现以下错误
ALTER TABLE `RMS`.`transactionentry`
CHANGE `Date` `Date` DATE DEFAULT NOW() NOT NULL
Run Code Online (Sandbox Code Playgroud)
错误
Invalid default value for 'Date'
Run Code Online (Sandbox Code Playgroud)
同样的情况
alter table `RMS`.`transactionentry`
change `Date` `Date` date default 'CURRENT_DATE' NOT NULL
Run Code Online (Sandbox Code Playgroud) 通用方法
public <T, E> void saveOrUpdate(T entity, List<E> list) throws DataAccessException {
Session session = sessionFactory.getCurrentSession();
session.saveOrUpdate(entity);
for(E getlist : list){
session.saveOrUpdate(getlist);
}
}
Run Code Online (Sandbox Code Playgroud)
(以下)控制器工作正常
@Controller
public class FinGeneralJournalController {
protected static Logger log = Logger
.getLogger(FinGeneralJournalController.class);
@Resource(name = "PersistenceTemplate")
private PersistenceTemplate pt;
@RequestMapping(value = "/AddFinGeneralJournal", method = RequestMethod.POST)
public @ResponseBody
JsonResponseStatus addGeneralJournalEntry(
@RequestParam(value="description", required=true) String description,
@RequestParam(value="trxDate", required=true) Date trxDate,
@RequestParam(value="sourceDocumentId", required=true) long sourceDocumentId,
@RequestParam(value="currencyId", required=true) long currencyId,
@RequestParam(value="batchId", required=true) long batchId,
@RequestParam(value="tableList", required=true) String …Run Code Online (Sandbox Code Playgroud) 我正在使用aspectj的自定义注释.
@TestLoggingAnnotation(setMessage = "I want to set value here")
public void get() {
String retString = null;
String message = "DEFAULT";
if (message == "DEFAULT") {
retString = "Default Logging";
} else {
retString = "Custom Logging";
}
}
Run Code Online (Sandbox Code Playgroud)
以上只是简单的示例代码.我的要求是我想在方法产生之后传递参数值.
在我的情况下,我想在自定义参数中设置retString值setMessage.
java ×5
hibernate ×2
mysql ×2
spring-mvc ×2
xml ×2
annotations ×1
controller ×1
datagridview ×1
date ×1
default ×1
exception ×1
faces-config ×1
jackson ×1
jboss-tools ×1
jdbc ×1
jquery ×1
jsf ×1
jsf-2 ×1
json ×1
printing ×1
service ×1
spring ×1
string ×1