机械制造企业成本分析计算表、产品生产销售成本计算表如何核算分析及公式,邮箱2735941080@qq.com,非常感谢

mybaits动态SQL中的DECIMAL -
- ITeye技术网站
博客分类:
数据库:mysql数据库字段类型:decimal(11,2)java程序类型:java.math.BigDecimal
使用mybatis的动态语句
&if test ="money!= null&,money&/if&
问题点:如果money传入的是0,那么动态语句也直接当做null处理
DECIMAL是压缩的“严格”定点数。null时取得的值是0,反过来0传入的时候,mybatis认为是null
浏览: 42421 次
来自: 杭州
&beans:property name=&qu ...
/Bruce-Go ...
一直没有找出处理的办法不过后来由于业务的需要,需要做一个每天都 ...
连接池自己改,取链接前检查,如果无效,则重新获取连接。apac ...
楼主你最后怎么解决的?> 关于mybatis的使用之怎么传递参数总结(一)
关于mybatis的使用之怎么传递参数总结(一)
iris0420 & &
发布时间: & &
浏览:1 & &
回复:0 & &
悬赏:0.0希赛币
关于mybatis的使用之如何传递参数总结(一)
  &第一个例子&
  修改删除这些没有返回值的操作,我们可以这样套用
  1,action得到前台传过来的参数,service如何使用参数。
  public void modifyUserRole(int userId, int roleId) {
Map&String, Object& paramMap = new HashMap&String, Object&();
paramMap.put("userId", userId);
paramMap.put("roleId", roleId);
userRoleMapper.modifyUserRole(paramMap);
  2,mapper.java和mapper.xml
  public void
modifyUserRole(Map&String, Object& map);
  &update id="modifyUserRole"
parameterType="java.util.HashMap"&
TS_USER_ROLE t set t.role_id=#{roleId} where t.user_id=#{userId}
  结语:这样就完了,就这么简单。
  &第二个例子&
  如果有返回值的,我们可以这样套用
  1,action直接把前台传过来的参数去调用service
  userRoleBean=this.userService.getUserRoleById(user.getId());
  2,接着传,这是service里面
  public UserRoleBean getUserRoleById(int userId) {
return this.userRoleMapper.getUserRoleById(userId);
  3,mapper.java和mapper.xml
  public UserRoleBean getUserRoleById(int userId);
  &select id="getUserRoleById" resultMap="userRoleResultMap"
parameterType="int"&
select * from TS_USER_ROLE
where user_id=#{userId}
  结语:接口的方法是用对象声明,mapper.mxl里面的resultMap也是这样返回。
  &第三个例子&
  如果此表里面的字段的外键是关联表的主键,那么,怎么相关联表的查询
  1,bean里面这样写
   // id
private S// 姓名
private String userN// 用户名
private S// 密码
private int unitId;// 单位编码
private int deptId;// 单位编码
private int userT// 用户类型
// 用户状态
private D// 部门
// deptId是外键,链接Dept表.
// 还是把所有字段声明完整,然后再添加一个成员变量
  2,,mapper.xml配置文件这样
  &resultMap id="userResultMap" type="com.zjedusoft.gdqs.bean.User"&
&id property="id" column="id" /&
&result property="name" column="NAME" /&
&result property="userName" column="USER_NAME" /&
&result property="password" column="PASSWORD" /&
&result property="unitId" column="UNIT_ID" /&
&result property="userType" column="USER_TYPE" /&
&result property="state" column="STATE" /&
&result property="deptId" column="DEPT_ID"/&
&result property="using" column="using"/&
&association property="dept" column="DEPT_ID" javaType="com.zjedusoft.gdqs.bean.Dept" resultMap="deptResultMap"/&
  然后使用是这样,这里多了其他的角色和权限,不管了,先贴上来吧。
  &select id="getAllUserByPage" resultMap="userResultMap" parameterType="java.util.HashMap"&
select zong.* from
select temp.*,rownum rownum_
select u.*,r.role_name as role_name,d.id as did,d.dept_name as dept_name
from ts_user_info u left join ts_user_role ur on u.id =ur.user_id
left join ts_role r
on ur.role_id=r.id
left join ts_dept d
u.dept_id=d.id
&if test="keyword != '%null%'"&
and u.USER_NAME
like #{keyword}
&if test="keyword != '%null%'"&
like #{keyword}
&if test="keyword != '%null%'"&
or d.dept_name
like #{keyword}
order by u.id
where rownum &= #{maxResult}
where zong.rownum_ & #{skipResult}
  3,再看action,service,mapper都和其他一样
  public List&User& getAllUserByPage(Map&String, Object& map);
  &第四个例子&
  那多对多,一对多怎么办呢。下面看。
  1,还是bean里面
  //多表查询,要把需要查询的collection当做属性get/set
private UserRoleBean userRoleB
private RoleBean
private RolePopedomBean rolePopedomB
private PopedomBean popedomB
p// 是否被使用中
  2.mapper.xml里面的
  &collection property="userRoleBean" ofType="com.zjedusoft.gdqs.bean.UserRoleBean"&
&id property="id" column="id" /&
&result property="userId" column="USER_ID" /&
&result property="roleId" column="ROLE_ID" /&
&/collection&
&collection property="roleBean" ofType="com.zjedusoft.gdqs.bean.RoleBean"&
&id property="id" column="id" /&
&result property="roleName" column="ROLE_NAME" /&
&result property="roleComments" column="ROLE_COMMENTS" /&
&result property="state" column="STATE" /&
&/collection&
&collection property="rolePopedomBean" ofType="com.zjedusoft.gdqs.bean.RolePopedomBean"&
&id property="id" column="id" /&
&result property="roleId" column="ROLE_ID" /&
&result property="popedomId" column="POPEDOM_ID" /&
&/collection&
&collection property="popedomBean" ofType="com.zjedusoft.gdqs.bean.PopedomBean"&
&id property="id" column="id" /&
&result property="LevleCode" column="LEVEL_CODE" /&
&result property="ParentId" column="PARENT_ID" /&
&result property="PopedomName" column="POPEDOM_NAME" /&
&result property="Url" column="URL" /&
&result property="PopedomComments" column="POPEDOM_COMMENTS" /&
&result property="type" column="TYPE" /&
&result property="state" column="STATE" /&
&/collection&
&/resultMap&
  然后还是这样,呵呵。
  &select id="getAllUserByPage" resultMap="userResultMap" parameterType="java.util.HashMap"&
select zong.* from
select temp.*,rownum rownum_
select u.*,r.role_name as role_name,d.id as did,d.dept_name as dept_name
from ts_user_info u left join ts_user_role ur on u.id =ur.user_id
left join ts_role r
on ur.role_id=r.id
left join ts_dept d
u.dept_id=d.id
&if test="keyword != '%null%'"&
and u.USER_NAME
like #{keyword}
&if test="keyword != '%null%'"&
like #{keyword}
&if test="keyword != '%null%'"&
or d.dept_name
like #{keyword}
order by u.id
where rownum &= #{maxResult}
where zong.rownum_ & #{skipResult}
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&解决问题的场景:执行人名字中含有_ 的,在查询中用_或含有_ 的字段,列表中查不到信息解决问题的思路:获取从MyBatis的mapper Xml文件中,找到原始的Sql语句(条件判断处理已好的SQL),在含有Like的查询字段值里若包含特殊字符,则转义 ,并在查询条件后面添加 " ESCAPE '/'。处理后的Sql语句类似:select * from from
syslog where t like '%\_条件值%' " ESCAPE '/'
OPER_REMARK
like '%\_条件值%' " ESCAPE '/'关键点:要获取原始SQL ,根据查询条件动态地修改SQL及参数值代码部分:拦截器基础:配置:&plugin interceptor="xxx.mybatis.plugin.PaginationInterceptor"&
&property name="dialect" value="oracle" /&
&property name="pageSqlId" value=".*ListPage.*" /&
&property name="exampleDialect" value="exampleOracle" /&
&property name="examplePageSqlId" value="selectByExample" /&
&/plugin&sqlMapper配置&select id="getListPage" resultMap="BaseResultMap"&
select &include refid="Base_Column_List" /&
from syslog
&if test="directoryId != null and directoryId !='' "&
and DIRECTORY_ID = #{directoryId}
&if test="operRemark != null and operRemark != '' "&
and OPER_REMARK LIKE '%' || #{operRemark} || '%'
&/if&拦截器主体代码:public Object intercept(Invocation invocation) throws Throwable {
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, DEFAULT_OBJECT_FACTORY,DEFAULT_OBJECT_WRAPPER_FACTORY);
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
MetaObject metaMappedStatement = MetaObject.forObject(mappedStatement, DEFAULT_OBJECT_FACTORY2,DEFAULT_OBJECT_WRAPPER_FACTORY2);//调用代码获取原始SQL并将其修改,参数值也BoundSql boundSql = statementHandler.getBoundSql();//原始sql对象
// 修改参数值
SqlNode sqlNode = (SqlNode) metaMappedStatement
.getValue("sqlSource.rootSqlNode");&span style="white-space:pre"&
&/span&//修改后的SQL对象
boundSql = PaginationInterceptor.getBoundSql(mappedStatement.getConfiguration(),
boundSql.getParameterObject(), sqlNode);获取SQLpublic static BoundSql getBoundSql(Configuration configuration,Object parameterObject,SqlNode sqlNode) {
DynamicContext context = new DynamicContext(configuration, parameterObject);
//DynamicContext context = new DynamicContext(mappedStatement.getConfiguration(), boundSql.getParameterObject());
//mappedStatement.getSqlSource().
sqlNode.apply(context);
String countextSql=context.getSql();//
System.out.println("context.getSql():"+countextSql);
SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
Class&?& parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
String sql=modifyLikeSql(countextSql, parameterObject);
SqlSource sqlSource = sqlSourceParser.parse(sql, parameterType, context.getBindings());
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
for (Map.Entry&String, Object& entry : context.getBindings().entrySet()) {
boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
return boundS
} 修改参数值:public static String modifyLikeSql(String sql,Object parameterObject) {
if(parameterObject instanceof HashMap){
if(!sql.toLowerCase().contains("like"))
//sql=" and OPER_REMARK LIKE '%' || #{operRemark} || '%'
\n " +"and OPER_U_NAME LIKE #{operUName} || '%' ";
//原始表达式:\s\w+\sLIKE\s('%'\s\|{2})?\s*(#\{\w+\})\s*(\|{2}\s*'%')
String reg="\\s\\w+\\sLIKE\\s*('%'\\s*\\|{2}\\s*)?(#\\{\\w+\\})(\\s*\\|{2}\\s*'%')?";//"order\\s+by\\s+.+"
Pattern pattern = pile(reg,Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(sql);
List&String& replaceEscape=new ArrayList&String&();
List&String& replaceFiled=new ArrayList&String&();
while(matcher.find()){
replaceEscape.add(matcher.group());
int n = matcher.groupCount();
for (int i = 0; i &= i++)
output = matcher.group(i);
if(2==i&&output!=null)
replaceFiled.add(output.trim());
//sql = matcher.replaceAll(reg+" 1111");
for(String s:replaceEscape)
sql=sql.replace(s, s+" ESCAPE '/' ");
//修改参数
HashMap&String,Object& paramMab=(HashMap)parameterO
for(String s:replaceFiled)
//sql=sql.replace(s, " ? ");
// #{operUName} --&operUName
String key=s.replace("#{", "").replace("}", "");
Object val =paramMab.get(key);
if(val!=null &&val instanceof String&&(val.toString().contains("%")||val.toString().contains("_")))
val=val.toString().replaceAll("%", "/%").replaceAll("_", "/_");
paramMab.put(key.toString(), val);
}源代码文件如下:
如果您想留下此文,您可以将其发送至您的邮箱(将同时以邮件内容&PDF形式发送)
相关文章推荐
(Ctrl+Enter提交) &&
已有0人在此发表见解
&在& 17:04收藏到了
&&在信息爆炸的时代,您的知识需要整理,沉淀,积累!Lai18为您提供一个简单实用的文章整理收藏工具,在这里您可以收藏对您有用的技术文章,自由分门别类,在整理的过程中,用心梳理自己的知识!相信,用不了多久,您收藏整理的文章将是您一生的知识宝库!
· 蜀ICP备号-1mybatis常用jdbcType数据类型 - NaOH - ITeye技术网站
博客分类:
MyBatis 通过包含的jdbcType类型
UNDEFINEDTINYINT
NVARCHARSMALLINT
LONGVARCHAR
NCHARINTEGER
LONGVARBINARY
NCLOBBIGINT
Mybatis中javaType和jdbcType对应和CRUD例子
&resultMap type="java.util.Map" id="resultjcm"&
&result property="FLD_NUMBER" column="FLD_NUMBER"
javaType="double" jdbcType="NUMERIC"/&
&result property="FLD_VARCHAR" column="FLD_VARCHAR" javaType="string" jdbcType="VARCHAR"/&
&result property="FLD_DATE" column="FLD_DATE" javaType="java.sql.Date" jdbcType="DATE"/&
&result property="FLD_INTEGER" column="FLD_INTEGER"
javaType="int" jdbcType="INTEGER"/&
&result property="FLD_DOUBLE" column="FLD_DOUBLE"
javaType="double" jdbcType="DOUBLE"/&
&result property="FLD_LONG" column="FLD_LONG"
javaType="long" jdbcType="INTEGER"/&
&result property="FLD_CHAR" column="FLD_CHAR"
javaType="string" jdbcType="CHAR"/&
&result property="FLD_BLOB" column="FLD_BLOB"
javaType="[B" jdbcType="BLOB" /&
&result property="FLD_CLOB" column="FLD_CLOB"
javaType="string" jdbcType="CLOB"/&
&result property="FLD_FLOAT" column="FLD_FLOAT"
javaType="float" jdbcType="FLOAT"/&
&result property="FLD_TIMESTAMP" column="FLD_TIMESTAMP"
javaType="java.sql.Timestamp" jdbcType="TIMESTAMP"/&
&/resultMap&
Mybatis中javaType和jdbcType对应关系
LONGVARCHAR
java.math.BigDecimal
java.math.BigDecimal
LONGVARBINARY
java.sql.Date
java.sql.Time
java.sql.Timestamp
mapping of underlying type
java.net.URL[color=red][/color]
浏览 136848
ysj5125094
浏览: 688351 次
来自: 沈阳
Java实现导入导出excel文件,利用poi实现感觉代码比较 ...
部署之后启动有问题org.springframework.be ...
谢谢分享。部署之后启动有问题org.springframewo ...
beancopier只实现了浅拷贝的功能,如果要实现深拷贝,则 ...本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 销售成本的计算公式 的文章

 

随机推荐