Java Code Examples for org.nutz.dao.sql.Sql#setEntity()

The following examples show how to use org.nutz.dao.sql.Sql#setEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 查询用户菜单
 *
 * @param userId 用户id
 * @return 菜单
 */
@Override
public List<Menu> getMenuList(String userId) {
    String sqlstr = "select distinct m.id, m.parent_id, m.menu_name, m.url, m.perms , m.menu_type, m.icon, m.order_num, m.create_time " +
            "from sys_menu m " +
            "left join sys_role_menu rm on m.id = rm.menu_id " +
            "left join sys_user_role ur on rm.role_id = ur.role_id " +
            "left join sys_role ro on ur.role_id = ro.id " +
            "where ur.user_id = @userId and m.menu_type in ('M', 'C') and m.visible = '0' " +
            "order by m.order_num";
    Sql sql = Sqls.create(sqlstr);
    sql.params().set("userId", userId);
    sql.setCallback(Sqls.callback.entities());
    Entity<Menu> entity = dao().getEntity(Menu.class);
    sql.setEntity(entity);
    dao().execute(sql);
    return sql.getList(Menu.class);
}
 
Example 2
Source File: GenServiceImpl.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 根据表名称查询信息
 *
 * @param tableName
 * @return
 */
private TableInfo selectTableByName(String tableName) {
    String sqlstr = "select table_name, table_comment, create_time, update_time from information_schema.tables " +
            "where table_comment <> '' and table_schema = (select database()) and table_name = @tableName";
    Sql sql = Sqls.create(sqlstr);
    sql.params().set("tableName", tableName);
    sql.setCallback(Sqls.callback.entities());
    Entity<TableInfo> entity = dao.getEntity(TableInfo.class);
    sql.setEntity(entity);
    dao.execute(sql);
    return sql.getObject(TableInfo.class);
}
 
Example 3
Source File: GenServiceImpl.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 根据表名称查询列信息
 *
 * @param tableName 表名称
 * @return 列信息
 */
private List<ColumnInfo> selectTableColumnsByName(String tableName) {
    String sqlstr = "select column_name, data_type, column_comment from information_schema.columns " +
            "where table_name = @tableName and table_schema = (select database()) order by ordinal_position";
    Sql sql = Sqls.create(sqlstr);
    sql.params().set("tableName", tableName);
    sql.setCallback(Sqls.callback.entities());
    Entity<ColumnInfo> entity = dao.getEntity(ColumnInfo.class);
    sql.setEntity(entity);
    dao.execute(sql);
    return sql.getList(ColumnInfo.class);
}